Saturday, June 4, 2016

How to Qualify Lead without creating Opportunity/Account/Contact in Microsoft Dynamics CRM

How to prevent MS CRM from creating Opportunity/Account/Contact while qualifying a Lead.

A lot of sales teams are frustrated with how lead conversion works in Microsoft Dynamics CRM.  Starting with CRM 2013, whenever a user clicks the “Qualify” button, an Opportunity is always created.  We were hoping to see a fix in CRM 2016 but, sadly, the process still works the same.

How can an organisation reconfigure Microsoft Dynamics CRM to allow sales to qualify a lead without creating an opportunity?

The qualify process built into Microsoft Dynamics CRM assumes that the lead conversion process always ends either in disqualification, or in the creation of an opportunity.  But most businesses have lead conversion scenarios that don’t end in the creation of an opportunity.  Consider the following:

A new contact from an existing account visits the website and completes a contact us form (perhaps requesting a downloadable resource, without any intent to purchase anything at this time).  Sales wants this lead to be visible on the account, so they would like to convert the lead and create a contact, but without creating an opportunity.

Inside Sales qualifies incoming leads, and then passes them along to Field Sales for ongoing contact.  Oftentimes a lead is qualified, but is not yet in the market to make a purchase.  Field Sales still wants to be able to work this prospect, but they don’t work with leads  (only accounts and contacts). They need to convert a lead into an account and contact, but without creating an opportunity.

There are many more scenarios like the two above. 

How can the sales department fix CRM to work the way that they do, instead of being forced to work the way CRM does?

Sometimes what developers does is that they create a custom button on Lead entity ribbon and Write a plugin code using  QualifyLeadRequest Class where they set what to create and what not (among Account/Contact/Opportunity).

Although it serves the purpose,but we have a better solution where we need not to Qualify Lead using different code by calling a plugin from custom button, instead we tell system what to create and what not.
What we need to do is to register a plugin on QualifyLead message on pre-event on lead and set CreateOpportunity/CreateAccount/CreateContact false.

Here what we got is, we need not to hide system Qualify button and neither we need to create other custom button to qualify lead.

Below is the code snippet where i have prevented Lead from creating Opportunity and Account:


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;
                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)
                    // set to true by default 
                    contextPlugin.InputParameters["CreateOpportunity"] = false;
                    // set to true by default 
                    contextPlugin.InputParameters["CreateAccount"] = false;   
            catch (InvalidPluginExecutionException ex)
                throw new InvalidPluginExecutionException(ex.Message);
            catch (Exception ex)
                throw new InvalidPluginExecutionException(ex.Message);

If we prevent Account/Contact creation this solution works great,but It have a little issue when we prevent it from creating Opportunity.

In this case there is no opportunity Created to which Lead page can redirect to it keps displaying Lead page.

Now if user clicks Qualify again, system throw error that you can't qualify a already qualified Lead.

But, we have a solution for this as well.

What we can do is write a JavaScript code on Form OnSave event which refresh the form:

var entityname =;
var entityid;
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();

        // 16 will pass on Lead Qualify button click
        if (SaveMode == SaveEventVal) {
            setTimeout(function () {
    var entityname =;
    var entityid;

            }, 1);
Hope it would be helpful.

No comments:

Post a Comment

Get files of last hour in Azure Data Factory

  Case I have a Data Factory pipeline that should run each hour and collect all new files added to the data lake since the last run. What is...