2

我正在为 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

我希望我没有错过任何东西。任何帮助将不胜感激:)谢谢

4

1 回答 1

2

好的,我终于设法解决了这个问题。它一直盯着我的脸 :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

于 2012-07-31T08:09:26.420 回答