Hi everyone I am new to CRM
I am want to know how to write a c#plugin when the lead qualify it is creating an account,
when I add a competitor to the lead, now if I qualify the lead I want to pass the competitor to the newly created account...
please help me!
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
Hello,
You will have to proceed this way:
1- Create a plugin OnPostOperation of create of Account
2- Get the Lead that it's associated to your newly Created Account
3- Get list of Competitors associated to the Lead.
4- Associate the Competitors to your newly Created Account.
These Operation can be done with the following requests:
2- Retrieve to get the Lead.
3- Retrieve Multiple to get List of Competitors
4- AssociateRequest to Associate Competitors to your Account
You can use this link to see how to create a Plugin
Please Mark as Veirified if it helped You :)
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156