Search code examples
c#data-migrationdynamics-crm-onlinedataverse

Migrating Dataverse records - Assigning value to regardingobjectidname on email entity using C#


I am migrating email records from one Dataverse environment to another. I am having problems assigning a value to regardingobjectid.Name. I get no error assigning the value, but in the target environment the value is NULL after assigning the value. Lookup columns like ownerid or createdby get the name value set without assigning the value. The record referenced in regardingobjectid is already present in the target environment.

Any tip or advice appreciated.

Here is the code used:

var newEntityReference = new EntityReference("custom_entity", new Guid(regardingObjectId))
 {
     Name = regardingObjectIdName
 };
 targetEntity["regardingobjectid"] = newEntityReference;

I also tried to assign the Name value like this but the result is the same.


 targetEntity["regardingobjectidname"] = "This is an email";


Solution

  • The EntityReference.Name property is ignored when it is supplied in a create or update operation. The system populates this property in Retrieve and RetrieveMultiple operations. In these read operations the Name property is populated with the value found in the primary name column of the targeted table.

    When the regarding object does not have its primary name set, the display name of the lookup referencing it will appear to be empty.