Error, ‘0 is not a valid CRM type code’ resolved in Dynamics CRM

By | March 17, 2016

Introduction:

While migrating data of the custom entities and its associated records like activities, notes, etc. from the source system to the target CRM, a difference is observed in the regardingobjecttypecode for all the custom entities in the source as well as the target CRM. When the entity is created, a unique integer value, Entity Type Code is assigned to every entity. So while migrating the data associated with the custom entities a custom code needs to be written in our migration tool to set ‘Regarding’ for these records.

Let us see how the custom code is written.

  • We generally make use of the Script Component in SSIS and create the output column of the data type as ‘Integer’ since the regardingobjecttypecode is the integer value.
  • Next, the code is written to set regardingobjecttypecode for each custom entity that has been migrated to the target CRM in the script component.

Here, let’s consider a custom entity called ‘Project’ in the source CRM for which the associated activities and the entity data needs to be migrated to the target system.

In the code add the following function.

But, while migrating the activities we faced an error, ‘0 is not a valid CRM type code’.

After investigating this issue, we found that there were some email activities where ‘Regarding’ was blank.

So due to this, the RegardingObjectTypeCode was being set as ‘0’ for the output column created in the script component which is of data type, integer. Since, there is no entity present in CRM with the entity type code as ‘0’, an error occurred while processing these records.

Even though there was no regarding set in the source CRM system, we wanted to migrate these email activities to the target CRM. In order to resolve this issue, there was a need to set the output column as null if ‘Regarding’ was blank for the email in the target CRM. So, we found that we can set the value for the object type code either by providing the integer code or by providing the logical name of the entity.

So we then changed the data type of the ObjectTypeCode column of the script component from an integer to a string and then mapped the regardingobjecttypecode in the destination CRM with the logical name of the custom entity.

Let us take a look how we did this.

1. We changed the data type of the output column to ‘Unicode String’.

a. Next, we navigated to the Script Component →Right Click → Edit →

b. In the left pane of the script transformation window we then navigated to ‘Input and Outputs’ → Output 0 → Output Columns and selected the column, ObjectType.

c. Next, the data type was changed to ‘Unicode String’ and the length was provided.SSIS

2. The code was then modified to map the regardingobjecttypecode as the logical name of the custom entity. Here’s is the code snippet.

Now we mapped this output column ‘ObjectType’ to the column ‘regardingobjecttypecode’ field in destination CRM as shown in the screenshot below.migrating data through SSIS

Now if we have to migrate those email activities which don’t have the ‘Regarding’ in the source CRM, you would not face any errors and the activities would be migrated to the destination CRM successfully.

Conclusion:

We can map ‘objecttypecode’ by providing the logical name of the entity while migration of the data.

So while migrating the data (for e.g. activities, notes) associated with the custom entity, mapping the ‘objecttypecode’ with the logical name of the custom entity is preferred. Because, if the some of the associated records do not have ‘Regarding’ in the source CRM and there is a need to migrate this data to the destination CRM, then these records can be migrated to the target CRM successfully.

Don’t Forget to Drop By Our Booth No # 1000, At Microsoft Envision.

Leave a Reply