Advertisements

Archive

Posts Tagged ‘objectid’

Dynamics CE – Issue while updating ‘Annotation’ record using SDK

Other day, we encountered following error in our plug-in, which has the logic to retrieve and update the ‘objectid’ field (i.e., Associated record) of Annotation record.

‘new_myentity’ with ID XXX-XXXX-XXXX-XXX does not exists

Below is the plug-in code:

var entAnnotation=new Entity(“annotation”);
entAnnotation.Attributes[“objectid”] = new EntityReference(“new_myentity”,”{GUID}”);
crmService.Update(entAnnotation);

We are trying to update ‘objectid’ and from the error, its clear that Object ID (i.e.,GUID) of the ‘new_myentity’ entity does not exists in the application.

But we know that the GUID is of a valid ‘new_myentity’ entity, as that was retrieved using ‘Query Expression’ in previous plug-in statement.

Reason and Fix:

  • We must also set ‘objecttypecode’ field as the schema name of the ‘objectid’ of the Annotation record.
  • In our case, its ‘new_myentity’.
  • Below is the code of Annotation update setting ‘objecttypecode’ field.

var entAnnotation=new Entity(“annotation”);
entAnnotation.Attributes[“objectid”] = new EntityReference(“new_myentity“,”{GUID}”);
entAnnotation.Attributes[“objecttypecode”] = “new_myentity“;
crmService.Update(entAnnotation);

Issue was annoying and took sometime to troubleshoot and find the actual reason.

🙂

Advertisements