using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
namespace ITV
{
public class Itvitaly : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
IPluginExecutionContext contextplugin = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = factory.CreateOrganizationService(contextplugin.UserId);
if (contextplugin.MessageName != "QualifyLead") return;
OptionSetValue LeadStatecode = new OptionSetValue();
OptionSetValue LeadStatuscode = new OptionSetValue();
EntityReference LeadRef = null;
try
{
LeadRef = (EntityReference)contextplugin.InputParameters["LeadId"];
Entity Lead = service.Retrieve("lead", LeadRef.Id, new ColumnSet(true));
if (LeadRef.LogicalName != "lead") { return; }
LeadStatecode = Lead.GetAttributeValue<OptionSetValue>("statecode");
LeadStatuscode = Lead.GetAttributeValue<OptionSetValue>("statuscode");
if (LeadStatecode.Value == 0 && LeadStatuscode.Value == 1)
{
contextplugin.InputParameters["CreateOpportunity"] = false;
contextplugin.InputParameters["CreateAccount"] = true;
contextplugin.InputParameters["CreateContact"] = true;
}
}
catch (InvalidPluginExecutionException ex)
{
throw new InvalidPluginExecutionException(ex.Message);
}
catch (Exception ex)
{
throw new InvalidPluginExecutionException(ex.Message);
}
}
}
}
thanks for your help but I am very confused this plugin I wrote to avoid creating opportunity when the lead is qualified
how to get the related lead of newly created account and how to write the query to retrieve multiple competitors ,, thanks in advance , it will means a lot me if anyone helps to me