Plugins 尝试使用插件更改CRM 4.0上帐户的所有者

Plugins 尝试使用插件更改CRM 4.0上帐户的所有者,plugins,dynamics-crm-4,account,owner,Plugins,Dynamics Crm 4,Account,Owner,我正在为Microsoft Dynamics CRM 4创建一个插件,该插件将根据另一个查找字段的值更改帐户实体的所有者。现在,我已成功获取将作为帐户“所有者”的用户的GUID。到现在为止,一直都还不错。 当我试图更换所有者时,问题就出现了。我正在尝试使用AssignRequest,但它不起作用。当我尝试执行请求时,我在C#调试器上得到一个SoapException,Web服务输出一个对话框,说明: “找不到请求的记录,或者您没有足够的权限查看该记录” 下面是我正在使用的代码:

我正在为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 我在错误的地方输入了错误的身份证。我需要将'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个小时看了这本书,但今天我马上意识到:停顿一下,退一步,通常会有帮助;)