C# CRM运营后机会创建插件

C# CRM运营后机会创建插件,c#,dynamics-crm,C#,Dynamics Crm,我想制作一个插件,在创建Opportunity后将潜在客户的姓名插入到我的数据库中,然后将我的web服务返回的id保存到Opportunity notes中 我设法创建并部署了一个插件来从web服务插入,但我不知道如何获取所需的数据并保存返回的id。您能帮我吗 下面是我的代码,其中包含虚拟数据,用于测试web服务功能,它在保存opportunity后插入到我的数据库中 public void Execute(IServiceProvider serviceProvider) {

我想制作一个插件,在创建Opportunity后将潜在客户的姓名插入到我的数据库中,然后将我的web服务返回的id保存到Opportunity notes中

我设法创建并部署了一个插件来从web服务插入,但我不知道如何获取所需的数据并保存返回的id。您能帮我吗

下面是我的代码,其中包含虚拟数据,用于测试web服务功能,它在保存opportunity后插入到我的数据库中

public void Execute(IServiceProvider serviceProvider)
        {
            IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext)); // Obtain the execution context from the service provider.                
            IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory)); // Obtain the organization service reference.                
            IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

            if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
            {
                // Obtain the target entity from the input parameters.
                Entity entity = (Entity)context.InputParameters["Target"];

                // Verify that the target entity represents an opportunity.                   
                if (entity.LogicalName != "opportunity")
                    return;

                nom = "Jerry";
                app = "Seinfeld";
                apm = "Costanza";                                       

                crmPlugins.crmPlugInsert.WebReference.websCRM webService = new crmPlugins.crmPlugInsert.WebReference.websCRM();
                folioS = webService.Insert(nom, app, apm);
            }
        }

如果我正确理解了您的问题,目标实体将拥有详细信息,您必须在使用web服务创建时提取所需信息并将其分配到nom、app和apm中

一旦它被创建,您就有了在对开本中创建的Id,使用下面的代码在opportunity record中创建关联的便笺

            Entity annotation = new Entity("annotation");

            annotation.Attributes["objectid"] = new EntityReference("opportunity", new Guid(entity.Id));
            annotation.Attributes["objecttypecode"] = "opportunity";
            annotation.Attributes["subject"] = "Prospect note";
            annotation.Attributes["notetext"] = folioS;

            crmService.Create(annotation);

我收到AccessRights:WriteAccess Detail的拒绝访问警报。我是否必须执行其他操作才能创建或更新值?@user3063952确保安全角色在opportunity、annotation等中拥有必要的特权和访问权限,无论您使用什么。。