繁体   English   中英

CRM后期操作机会创建插件

[英]CRM Post Operation Opportunity Create Plugin

我想制作一个插件,在创建机会后,将潜在客户的名字插入我的数据库,然后将我的Web服务返回的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);
            }
        }

如果我正确理解了您的问题,目标实体将提供详细信息,您必须在使用Web服务创建时提取所需的信息并将其分配给nom,app和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);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM