Qualify Lead without Opportunity in Microsoft Dynamics CRM using C#
Introduction
We had a dialog box in Microsoft CRM 2011, which we used to create Accounts, Contacts, and Opportunities in the Lead Qualification process.
Learn more about our Microsoft Dynamics 365 Services

However, this dialog box has been deprecated, and we no longer have this dialog box in Dynamic 365 Sales.
Qualify Lead in Dynamics 365 Sales
Now, inside the lead form in CRM, there are two fields named “Existing Contact” and “Existing Account”, and we use these fields to add related Contact or Account.
Streamline your Lead Management Process!
Begin your journey with AlphaBOLD to streamline your processes using Microsoft Dynamics CRM. Experience how our tailored solutions can revolutionize your lead management.
Request a DemoAdhoc Lead Qualify Process
This is a very useful design to optimize flow based on business requirements. If a record already exists, the system uses it to associate qualified leads rather than creating a new one. However, it depends on how you implement it and the business requirements. Sometimes, we don’t want to create new opportunities as part of the lead qualification process. In addition, we also need lead qualification without an account or contact creation at times. Moreover, if the implementation uses xRM as a platform, business requirements might govern the creation of a completely new entity record on lead qualification (not covered). Therefore, to tackle the above-mentioned problem, we are giving a solution using a plugin and JS for Dynamics 365 that would help users qualify leads without creating opportunities, accounts, or contacts.
Plugin Code:
public void Execute(IServiceProvider serviceProvider)
{
IPluginExecutionContext context =
(IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory serviceFactory =
(IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
service = serviceFactory.CreateOrganizationService(context.UserId);
if (context.MessageName != “QualifyLead”) return;
OptionSetValue LeadStatecode = new OptionSetValue();
OptionSetValue LeadStatuscode = new OptionSetValue();
EntityReference LeadRef = null;
try
{
// Get the qualified lead
LeadRef = (EntityReference)context.InputParameters[“LeadId”];
if (LeadRef.LogicalName != “lead”) { return; }
ColumnSet attributes = new ColumnSet(new string[] { “statecode”, “statuscode” });
Entity lead = service.Retrieve(LeadRef.LogicalName, LeadRef.Id, attributes);
LeadStatecode = Lead.GetAttributeValue<OptionSetValue>(“statecode”);
LeadStatuscode = Lead.GetAttributeValue<OptionSetValue>(“statuscode”);
if (LeadStatecode.Value == 0 && LeadStatuscode.Value == 1)
{
context.InputParameters[“CreateOpportunity”] = false;
context.InputParameters[“CreateAccount”] = false;
context.InputParameters[“CreateContact”] = false;
}
}
catch (Exception ex)
{
throw new InvalidPluginExecutionException(“An error occurred in the Plugin.” + ex, ex);
}
}
Register this plugin at the ‘QualifyLead’ Message at ‘Pre-Operation’.
The above code works fine. However, the lead form freezes when we trigger it from the Qualify Lead Button. So, we need to refresh the page after performing this operation. It means we apply the below JS on “onload” event of the lead Form.
JavaScript Code:
For the solution, I wrote a webresource of type JScript with the following code.
var entityname = Xrm.Page.data.entity.getEntityName();
var entityid =Xrm.Page.data.entity.getId();
Xrm.Utility.openEntityForm(entityname,entityid);function refresh(Context) {
var SaveMode, SaveEventVal;
// Change the Save Event Value as per required Save Event
SaveEventVal = 16;
if (Context != null && Context.getEventArgs() != null) {
SaveMode = Context.getEventArgs().getSaveMode();
//On Lead Qualify button click
if (SaveMode == SaveEventVal) {
setTimeout(function () {
var entityname = Xrm.Page.data.entity.getEntityName();
var entityid =Xrm.Page.data.entity.getId();
Xrm.Utility.openEntityForm(entityname,entityid);
}, 1);
}
}
}
This will solve the above-mentioned issue; they all work fine in the background.
Read more: AI in CRM: Exploring Microsoft Dynamics 365 Benefits
Transform your Lead Qualification with Expert Insights!
Eager to refine your lead qualification process in Microsoft Dynamics CRM? With AlphaBOLD, gain access to expert insights and bespoke C# solutions that can elevate your CRM strategy.
Request a DemoConclusion
So, we can avoid the creation of the records while performing the Lead qualifying process in Dynamics 365 by simply registering a plugin at the Qualify message and applying a JS on the load of the Lead Page.
If you have any questions or queries, please contact us!
Explore Recent Blog Posts
