Microsoft Dynamics CRM Annotation Entity wrong "Created by" Field value

341 views Asked by At

I am working with Dynamics CRM annotation, i developed an external application that use the organization service in order to create new annotation linked to a custom entity and linked to the user based on the user id, by set the CallerId in the organization Service and by set the field "CreatedBy" in the annotation object on create.

The problem is that the annotation is sometimes the value of "Created by" is not correct and it randomly set it by another user.

below used code:

 Guid callerID = new Guid(HttpContext.Current.Request.QueryString["CallerId"].ToString());


 CrmServiceClient connection = new CrmServiceClient(connectionString);
 OrganizationServices = connection.OrganizationServiceProxy;
 OrganizationServices.CallerId = new Guid(callerID);
 .
 .
 .
 Entity Annotation = new Entity("annotation");
 Annotation.Attributes["objectid"] = new EntityReference("RelatedEntityLogical", RelatedEntity.Id);
 Annotation.Attributes["objecttypecode"] = RelatedEntity.LogicalName;
 .
 .
 .
 Annotation.Attributes["createdby"] = new EntityReference("systemuser", callerID);
 
 OrganizationServices.Create(Annotation);

Any ideas? Thanks

1

There are 1 answers

4
Aron On

Maybe try this:

Do not set the createdby attribute - i.e. remove this line:
Annotation.Attributes["createdby"] = new EntityReference("systemuser", callerID);

Set the CallerId directly on the instance of CrmServiceClient:
connection.CallerId = new Guid(callerID);

Invoke Create directly from the instance of CrmServiceClient:
connection.Create(Annotation);