简体   繁体   English

CRM后期操作机会创建插件

[英]CRM Post Operation Opportunity Create Plugin

I want to make a plugin that inserts into my database the prospect's name after the Opportunity is created, and then save into the opportunity notes the id returned by my web service. 我想制作一个插件,在创建机会后,将潜在客户的名字插入我的数据库,然后将我的Web服务返回的ID保存到机会注释中。

I managed to create and deploy a plugin to insert from a web service, but I do not know how get the data I want, and save the returned id. 我设法创建并部署了从Web服务插入的插件,但是我不知道如何获取所需的数据并保存返回的ID。 Can you help me? 你能帮助我吗?

Here's my code with dummy data to test the web service functionality, it inserts into my database after the opportunity is saved. 这是我的带有伪数据的代码,用于测试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);
            }
        }

If I understand your question correctly, Target entity will have the details, you have to pull the needed information & assign it in nom, app & apm while creating using web service. 如果我正确理解了您的问题,目标实体将提供详细信息,您必须在使用Web服务创建时提取所需的信息并将其分配给nom,app和apm。

Once it's created you have the created Id in folioS, use it to create associated note in opportunity record using below code. 创建后,您就在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