Archive
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.
🙂
Adding “Notes” to the “Quote” progrmatically in CRM 2011
//Instantiate ‘Entity’ and set the ‘LogicalName’ to “annotation”
Entity objNotes = new Entity();
objNotes.LogicalName = “annotation”;//Set ‘Subject’ and ‘notetext (i.e.,Body)’ properties
objNotes.Attributes.Add(“subject”, ”—-Your Subject—”);
objNotes.Attributes.Add(“notetext”, “—Your notes text—”);//Relate the note with ‘Quote’ using ‘EntityReference’
EntityReference refQuote = new EntityReference();
refQuote.LogicalName = “quote”;
refQuote.Id = quoteID; //Quote GUID
objNotes.Attributes.Add(“objectid”, refQuote);//Set “objecttypecode” property with “quote” objecttypecode (i.e.,1084)
//Refer http://technet.microsoft.com/en-us/library/ms955729.aspx for objecttypecode’s
objNotes.Attributes.Add(“objecttypecode”, 1084);//Call CRMService ‘Create’ method
crmService.Create(objNotes);