CRM Post Operation Opportunity创建插件

时间:2018-02-12 16:46:10

标签: c# dynamics-crm

我想创建一个插件,在创建商机后将潜在客户的名称插入我的数据库,然后将我的网络服务返回的ID保存到机会注释中。

我设法创建并部署了一个从Web服务插入的插件,但我不知道如何获取我想要的数据,并保存返回的id。你能救我吗?

这是我的代码,用于测试Web服务功能的虚拟数据,在机会保存后插入到我的数据库中。

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);
            }
        }

1 个答案:

答案 0 :(得分:1)

如果我正确理解您的问题,目标实体将拥有详细信息,您必须提取所需信息&将它分配给nom,app&在使用Web服务创建时使用apm。

创建后,您在folioS中拥有创建的ID,使用它在机会记录中使用以下代码创建相关注释。

            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);
相关问题