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

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.

public override void Input0_ProcessInputRow(Input0Buffer Row)
{
if (!Row.regardingobjecttypecode_IsNull)
{
//check if the regardingobjecttypecode for the record in source crm is the Project entity
if(Row.regardingobjecttypecode==10143)
{
//set the object type code to the o/p column
Row.ObjectTypeCode = "10142"; //object type code of the Project entity in destination CRM
}
}
}

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.

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.

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.

Your email address will not be published. Required fields are marked *

Comment

Name *

Email *

Website

Follow Us!

Search for:

About Us

With a Silver competency and cumulative experience of 30 years, Inogic has earned the recognition as a Microsoft Dynamics CRM solution provider. Our team creates a better future for businesses spread across various industrial sectors. We are not only the innovators for CRM add-ons like Maplytics™(Certified for Microsoft Dynamics) and InoLink but also provide back office support for our partners. Read more about us.