簡體   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