Showing posts with label Scribe Data Migration. Show all posts
Showing posts with label Scribe Data Migration. Show all posts

Monday, June 29, 2015

Scribe Data Migration Notes

  1. Before migrating record of any entity, create a text field, length 100, optional, in destination table (Account, Contact etc.). This filed will be used to capture the primary key GUID from source and will help us if we need to update/delete the migrated records later. You can give the key name as dataSourceId.
  2. Always put NVARCHAR fields like "description" etc. at the end of the column list in the SQL Query that is used to select the source data. Otherwise the value might be exported as NULL in destination even if it is present in source.
  3. For any entity, do not map statecode and statuscode fields initially. For these two fields, create another package and update the records after migrating the records without these two fields. This will allow creating the relationship between INACTIVE records, for e.g Order and Inactive products.
  4. No need to map owneridtypecode field. Just map ownerid to ownerid based on dblookup of owneridname field in the source.
  5. Make sure that you set the timezone to UTC/GMT in the package settings. Otherwise the migrated DateTime values will be inserted according to the timezone settings of the user which is used to connect the destination CRM in the Scribe Package. Follow these steps to avoid this scenario:
    • Open the properties of the CRM target connection and Navigate to the Connection tab.
    • Click the Adapter Settings button.
    • Navigate to the User/Owner tab.
    • Set the "Time zone to use for all date/time values" option to "UTC/GMT".
  6. Make sure to provide default values for required fields in the destination. For e.g. if source owner is not found in destination, substitute it with a dummy/default owner that is present in the destination.
  7. If you run the package and get an error "There is no active transaction. This error is usually caused by custom plug-ins that ignore errors from service calls and continue processing." try to see if “Bulk Mode” option in destination connection properties is checked. If that is the case, uncheck the bulk mode and re-run the package.
  8. If you get the error “Creating this parental association would create a loop in this entity hierarchy”, note down the records in the respective Scribe Rejected table and manually update the required fields in the destination CRM.
  9. For Optionsets or previously Picklists, when source values are different than the destination values, create an .ini file (e.g. SourceToDestinationOptionSets.ini)

    Let's say in source, the values are like this.
    1 = Quote Report
    2 = Product Report

    And in the destination, we have
    936710000 = Quote Report
    936710001 = Product Report.

    Then add source to destination field mapping in the .ini file like following:

    [New_ReportType]
    1=936710000
    2=936710001

    Here New_ReportType is the title (with square brackets) that will be used in the formula in Scribe package.

    After creating the file, add mapping formula as following:

    FILELOOKUP(S305,"SourceToDestinationOptionSets.ini","New_ReportType" )

    Remember to reopen the package file if it was already open when you created the package, otherwise this formula will give error.

    In the above formula, the S305 is the field reference number for the Record Type field in source.

Monday, June 22, 2015

Scheduling the Scribe Package

Scheduling can be used to automatically migrate any new record from source to destination as soon as it is created in the source. This process is also known as Scribe Integration. When we schedule the Scribe package, we do not need to run it manually by opening it in Scribe Workbench as shown in my previous article Data Migration from Microsoft SQL Database to Dynamics CRM.

This article assumes that you already have a Scribe package that is ready to be executed. If you do not have it, you can follow the aforementioned article to create one.

To schedule the scribe package, follow these steps.

 

Step 1: Update the Scribe Package

Click on "Configure Source" button.

Figure 1

A message box window will popup. Select "Keep existing links" radio option. Click OK button.
On the next window, select the "Source Keys" button.

Figure 2

You will get the following popup.

Figure 3

Click the button on the right of "Source Key Field(s)" as shown above. On the next window, select the primary key from the left column and move it to the right column.

Figure 4

Click OK. Repeat the same process for "Source Name Field(s)" button. You do not need to change the default options.

Now you will have the primary key in both fields. Select OK.

Figure 5

Click on "Update Source" button now. 

Figure 6

Make the selections as highlighted below. Then select OK.

Figure 7

On the next screen select OK as well.

Figure 8

Close the Scribe package.

Now open Scribe Console. The desktop icon looks like the following.

Figure 9

You will get the screen similar to the following. Select "Site Settings" as highlighted below.

Figure 10

Make sure that the "Collaborations root" path is valid. You can verify that by navigating to that folder using windows explorer.

Click Save. You might get this message "Changes to these settings will not take effect until scribe services are restarted." To restart services, you can manually go to services by using Run → services.msc and restart them or you can use the following approach that is described at this URL.
https://community.dynamics.com/crm/b/koorbconsultingteamblog/archive/2012/06/06/start-stop-scribe-service-using-batch-file.aspx

Right click ->New ->Text Document, Select text file and rename to StopScribe.bat
net Stop "Scribe Monitorserver"
net stop "Scribe MessageServer"
net stop "Scribe EventManager"
net stop "Scribe BridgeServer"
net Stop "Scribe AdminServer"

Right click ->New ->Text Document, Select text file and rename to StartScribe.bat
net start "Scribe AdminServer"
net start "Scribe BridgeServer"
net start "Scribe EventManager"
net start "Scribe MessageServer"
net start "Scribe MonitorServer"

Expand the default node under collaborations folder. This is how the folders are organized in windows explorer.

Figure 11

Copy your Scribe packages into this folder. If you want your packages on different path, make sure it appears/added into the Administration →Security → Console Shared Folders.
I recommend creating a new folder inside the Default folder as highlighted above to leave the scheduling process go smoothly.
Click Add button to add a new job.

Figure 12

In "Process Event" section, select the option as highlighted. Then select the "Browse" button. Make sure that you follow the previous steps correctly otherwise you might get this or similar error when you click the browse button.

Cannot browse c:\scribe\Scribe Collaborations not authorized by access settings.

Figure 13


Select your Scribe package and click "OK".
Change the Process name if required. Click on Step 2, 3, 4, 5. I did not have to change any values in the next steps. Click the "Finish" button at the bottom that should be enabled by now.


Figure 14

Now you can insert the record into CRM table by using the SQL Query or CRM. It should be automatically moved to the destination CRM after two minutes or 120 seconds.

Data Migration from Microsoft SQL Database to Dynamics CRM

In this article, I will discuss about migrating data from SQL Database to CRM. This article assumes that you have the following or equivalent:
  • Windows Server 2012 R2
  • Scribe Insight
  • Microsoft SQL Server 2012

Step 1: Creating Source ODBC Connection

  1. On Windows Server 2012, go to Control Panel → System and Security → Administrative Tools and select "ODBC Data Sources (32-bit)".
  2. Select "System DSN Tab". Click "Add" button.  In "Create New Data Source" window, select "SQL Server" and click the Finish button.
  3. Type in a name in "Name" field.
    Type "." (Dot without quotes) in "Server" dropdown.
    Select "Next", then "Next".
    Select the checkbox "Change the default database to" and from the dropdown, select the required database name.
    Select "Next" and select "Finish". Select "Test Data Source" button to verify if the operation is successful. Close the dialog.

Step 2: Creating Source SQL View

Create a view in SQL using the following code:

CREATE VIEW dbo.[ViewName]
AS
SELECT
        [ColumnNames]
        IsProcessed,
        Comments
FROM dbo.[TableName] WHERE IsProcessed = 0

The view ensures that you are only selecting the required columns to migrate. Note the "IsProcessed" and "Comments" columns. You will need to create the "IsProcessed" column in the source table using the following code before creating the view.

ALTER TABLE dbo.[TableName] ADD IsProcessed BIT NOT NULL DEFAULT(0)

The "Is Processed" column will be used to mark the processed records or the records that have been migrated. We will later see in this article how it is useful for scheduling the Scribe package.

The "Comments" column is a Text or Nvarchar field in SQL table. Always put the Nvarchar fields like "description" etc. at the end of the SELECT column list. Otherwise the values will be exported as NULL in the target CRM even if they are present in source. This is a limitation of Scribe and we cannot do much about it.

Step 3: Creating Field in Target CRM Entity

We are assuming that the data will be migrated from Contact table in SQL Database to the Contact entity in CRM. But before we create the Scribe package, we first need to create a Single Line of Text field, length 36, in the Contact entity in CRM. Let’s name it as dataSourceId. Note that the publisher name will be prefixed with this name so the name of the resulting field will be like mypub_dataSourceId. This field is helpful to delete the migrated data later if we face any issue or an error occurs while we execute our Scribe package. It is also helpful later to update the migrated data with the value of any missing field.

We also have the option to migrate the same GUIDs from source SQL table to destination CRM. In that case, we do not need the dataSourceId field to update the data but even then, we will not be able to track if the record has been migrated from SQL or the record has been created in CRM. Therefore, creating this field is always recommended.

Step 4: Creating the Scribe Package for Migration

Click Scribe Workbench icon to open a blank package file.
Figure 1

Now we need to specify the source and target connections for data migration.

Creating Source Connection

Click on Configure Source → Connections → Add as shown in the figure below:

Figure 2

Expand the "ODBC Data Sources" list item and select the name of ODBC Connection that you created in Step 1. Then select the OK button. On the next screen, leave the "Connection Name" as it is or change it if you want. Select OK and then select "Close"

On the next screen as shown below, select the connection name that you just created.

Figure 3


Expand the "Views" list item and select the view you created in Step 2. Select OK. The view columns should now be listed in the Source section of Scribe Package.

Save the package by selecting the Save Icon on the toolbar or using Ctrl+S key.

Creating Destination/Target Connection

Click on Configure Steps → Connections → Add button as shown in the figure below, and select "Microsoft Dynamics CRM" adapter. Then select OK.

Figure 4

On the next screen as shown below, enter the required information.
Figure 5

In the above screenshot:
  • The server URL is the base URL of your CRM Website, for e.g. http://www.yourcrm.com/.
  • Organization name can be retrieved by going to Settings → Customizations → Developer Resources. Then look for the value under the "Organization Unique Name".
  • User and Password values are same as used to log on to the CRM.
Select OK. On the next screen, change the connection name to "DestinationCRM" or whatever you like. Select OK. Then select Close.

On the next screen, select the new CRM connection that you just created. Then select the entity into which you want to migrate the data, in this case it is "contact". Then add the "Update/Insert" step as shown below.


Figure 6

As you can see in the above screenshot, the exclamation mark in the step box shows we need to fix something. For that, after selecting the "Close" button, select the "Lookup Criteria" tab as shown in the figure below. Then select the ContactId from source and dataSourceId from the target and select the "Lookup Link" button.


Figure 7

The Lookup field should now appear under the lookup tab. This tells the scribe to match the contact id in source with dataSourceId in destination. If they match, update the record, otherwise add a new record. It also implies that when we run the package for the first time, all the records will be created. After that if we execute the same package, the records will be updated as the contactId in source will be matched with dataSourceId in destination. If you again select the "Configure Steps" button, you will notice that the exclamation mark has disappeared.

Now we will map few sample fields to migrate the data. First select the "First Name" from source and "First Name" from target. Then select the "Data Link" button. This simply implies that migrate the first name in source to the first name in destination. Repeat the same steps for "Account Id" and "parentcustomerid", as shown in the figure below:

Figure 8

When we double click on the Step Name as highlighted in the figure above (point no. 4), the formula editor will open. Then, execute the steps as mentioned in the figure below:

Figure 9

Pay attention to the highlighted sections. The DBLookup function implies that pick the source value (S11), use the target connection "DestinationCRM", query the account entity and try to match the source value with accountid. If a match is found, return the accountid. If a match is not found, the DBLOOKUP function will return NULL. Select OK to close the window. If we translate the above formula into SQL, we will get the following:

SELECT accounted FROM DestinationCRM.account WHERE accountid = S11

You can map other fields as required and use different Scribe Insight functions. Use the link Scribe Insight Functions for further reference.

Before you run the package, make sure that you execute the steps as shown in the figure below:

Figure 10

This will ensure that if an error occurs while you execute the package, you will get all the information about the failed records and error description in the Scribe table (REJECTED_CONTACTS) that can be viewed through SQL Server Management Studio later on.

Note the "Test" and "Run Job" commands under the Run menu. It is always recommended to use the "Test" command initially to see the actual data that will be inserted after migration. It is also helpful to test see few records and identify any problems in the data and fix them before running the package.

After some testing, you can run the package by using the "Run Job" command. If you want to schedule the package without running it, close the package and see the next section Scheduling the Scribe Package for more information.