0

我正在使用 Dynamics CRM 注释,我开发了一个使用组织服务的外部应用程序,以便创建链接到自定义实体并根据用户 ID 链接到用户的新注释,通过在组织服务中设置 CallerId 并通过在创建时在注释对象中设置字段“CreatedBy”。

问题是注释有时“创建者”的值​​不正确,它是由另一个用户随机设置的。

下面使用的代码:

 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);

有任何想法吗?谢谢

4

1 回答 1

0

也许试试这个:

不要设置createdby属性 - 即删除此行:
Annotation.Attributes["createdby"] = new EntityReference("systemuser", callerID);

直接在 CrmServiceClient 的实例上设置CallerId :
connection.CallerId = new Guid(callerID);

Create直接从 CrmServiceClient 的实例调用:
connection.Create(Annotation);

于 2021-04-23T20:06:24.370 回答