我正在为 Microsoft Dynamics CRM 4 创建一个插件,该插件将根据另一个查找字段的值更改帐户实体的所有者。现在我已成功获取将充当帐户“所有者”的用户的 GUID。到目前为止,一切都很好。 当我尝试更换所有者时,问题就出现了。我正在尝试使用AssignRequest,但它不起作用。当我尝试执行请求时,我在 C# 调试器上收到 SoapException,并且 Web 服务输出一个对话框,指出: “找不到所请求的记录,或者您没有足够的权限查看它”
下面是我正在使用的代码:
TargetOwnedAccount target = new TargetOwnedAccount();
SecurityPrincipal assignee = new SecurityPrincipal();
assignee.Type = SecurityPrincipalType.User;
assignee.PrincipalId = context.InitiatingUserId;
target.EntityId = ownerGuid; //this is the GUID I am retrieving from the other lookup field
AssignRequest assign = new AssignRequest();
assign.Assignee = assignee;
assign.Target = target;
AssignResponse res = (AssignResponse)crmService.Execute(assign); //this is where i get the exception
我希望我没有错过任何事情。 任何帮助将非常感激 :) 谢谢
最佳答案
好吧,我终于解决了这个问题。它一直盯着我的脸:P 我在错误的地方输入了错误的 ID。我需要将“assignee.PrincipalId”设置为“ownerGuid”,然后将“target.EntityId”设置为当前帐户 ID。新代码如下:
TargetOwnedAccount target = new TargetOwnedAccount();
SecurityPrincipal assignee = new SecurityPrincipal();
assignee.Type = SecurityPrincipalType.User;
assignee.PrincipalId = ownerGuid; //this is the GUID I am retrieving from the other lookup field
target.EntityId = ((Key)entity.Properties["accountid"]).Value;
AssignRequest assign = new AssignRequest();
assign.Assignee = assignee;
assign.Target = target;
AssignResponse res = (AssignResponse)crmService.Execute(assign);
不敢相信我昨天花了 8 个小时看它,然后今天我立即意识到:P
关于plugins - 尝试使用插件更改 CRM 4.0 上的帐户所有者,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11724684/