SQL Server function to get Business Unit Guid by Name

This will be very useful when you are migrating data to CRM database from some other system database. Specially when filling base tables we should give business unit guid to it.
You can use following function and I have given the way that you should use it in your data migration scripts.
CREATE FUNCTION dmfx_GetBusinessUnit
(   
    @businessUnitName nvarchar(30)
)
RETURNS TABLE
AS
RETURN
    SELECT [BusinessUnitId] AS BusinessUnit
    FROM [TEST_MSCRM].[dbo].[BusinessUnitBase]
    WHERE Name=@businessUnitName
GO
Use\Invoke the above function as follows…

INSERT INTO [TEST_MSCRM].[dbo].[TEST_regionBase]
      (
      [CPMS_regionId]
      ,[CreatedOn]
      ,[CreatedBy]
      ,[ModifiedOn]
      ,[ModifiedBy]
      ,[OwningUser]
      ,[OwningBusinessUnit]
      ,[statecode]
      ,[statuscode]
      ,[DeletionStateCode]
      ,[ImportSequenceNumber]
      ,[OverriddenCreatedOn]
      ,[TimeZoneRuleVersionNumber]
      ,[UTCConversionTimeZoneCode] 
      )
SELECT
     [GUID] as TEST_regionId]
      ,GETDATE() AS [Created]
      ,(SELECT DataMigrationUser FROM dmfx_GetDataMigrationUserId()) AS [CreatedBy]    —    Data Migration User
      ,GETDATE() AS [Modified]                           
      ,(SELECT DataMigrationUser FROM dmfx_GetDataMigrationUserId()) AS [ModifiedBy]    —    Data Migration User
      ,(SELECT DataMigrationUser FROM dmfx_GetDataMigrationUserId()) AS [OwningUser]    —    Data Migration User
      ,(SELECT BusinessUnit AS [OwningBusinessUnit] FROM dmfx_GetBusinessUnit(‘TESTBUSINESSUNIT’)) AS BusinessUnit     —   
TESTBUSINESSUNIT
      ,0 AS [statecode]
      ,1 AS [statuscode]
      ,0 AS [DeletionStateCode]
      ,null AS [ImportSequenceNumber]
      ,null AS [OverriddenCreatedOn]
      ,0 AS [TimeZoneRuleVersionNumber]
      ,null AS [UTCConversionTimeZoneCode]

FROM [EXISTINGDB].[dbo].[ClientRegions]

Advertisements

Set CRM Date Field to Empty

I have a check box and a date field on the form. The requirement is to display the System Date in the date field when the check box is checked by the user and to clear the date field when the check box is unchecked by the user. Although the user has unchecked the check box and saved the form it displays the previously saved date by the user. I used the following code to save it.

Following code will solve the problem and will set it to Empty when it saved.

      //get the value of Reviewed by Manager checkbox
    var ReviewedManager = crmForm.all.cpms_reviewedbymanager.DataValue;

    //if Reviewed by Manager chekbox is checked
    if (ReviewedManager == true)
    {
        //set the Date Reviewed by  to system date
        crmForm.all.cpms_datereviewedbymanager.Disabled = false;
        crmForm.all.cpms_datereviewedbymanager.DataValue = new Date();
    }
    else
    {
        crmForm.all.cpms_datereviewedbymanager.DataValue = null;
        crmForm.all.cpms_datereviewedbymanager.ForceSubmit = true;
        crmForm.all.cpms_datereviewedbymanager.Disabled = true;
    }

Good Book for beginning OOP with C++


The Book named “Object-oriented Programming with C++” by E. Balagurusamy, one of the best books I have ever read to learn and understand object oriented concepts as a beginner. I read it in 2002 for the first time and it was the 2nd edition of that book. The author uses real life simple examples to teach and express the real meaning of object oriented concepts. At the end of every chapter he gives a summery of that particular chapter and review questions. Now the publisher has released its 3rd edition.

Programming With Java- A Primer is another good book written by the same author.

visit:www.tatamcgrawhill.com/digital_solutions/balagurusamy