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

标签 plugins dynamics-crm-4 account owner

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

相关文章:

jquery - 在 jQuery 插件中调用函数

workflow - 使用 3.0 标注和工作流程的 Microsoft Dynamics CRM 4.0

dynamics-crm - 左加入 FetchXml?

android - 获取用于应用内结算购买的 Google ID

azure - 在 Azure DevOps 中将个人帐户连接到组织帐户

file - 如何在命令行中为 maven 发布插件设置排除列表?

jquery - jquery最好的弹出框插件

plugins - Gradle:重新初始化/重新加载settings.gradle

dynamics-crm-2011 - 如何在crm 2011中表示图表的特定颜色

php - WooCommerce - 从我的帐户页面的菜单中删除下载