Monday, February 19, 2018

Get the Created Records when Lead Gets Qualified - Microsoft dynamics CRM

Hi All,

Once Lead Gets Qualify, as per oob behavior it will automatically create opportunity, contact and accounts.

As per my logic whenever an opportunity gets created need to set created lead id to custom opportunity field.

Plugin Step Creation:


Register Plugin as Asynchronously


            IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
            IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
            IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
            OrganizationServiceContext orgContext = new OrganizationServiceContext(service);

EntityReference getLeadid = (EntityReference)context.InputParameters["LeadId"];
Entity lead = service.Retrieve("lead", leadid.Id, new ColumnSet(true));

foreach (EntityReference CreatedEntityFromLead in ((IEnumerable)context.OutputParameters["CreatedEntities"]))
                {
                    if (CreatedEntityFromLead.LogicalName == "opportunity")
                    {
                        Entity entOpportunity = service.Retrieve("opportunity", CreatedEntityFromLead.Id, new ColumnSet(true));
                         entOpportunity["new_customLookupid"] = erLookUpField;
                        service.Update(entOpportunity);
                    }

                }




No comments:

Post a Comment

Day 11 - Customizing Option Sets Dropdown Fields with JavaScript

  In this Blog, we will see how to Customizing Option Sets Dropdown Fields with JavaScript label1 = formContext.getAttribute( "bosch_op...