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

this image shows Qualify Lead Process in CRM 2011

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.

this image shows Qualify Lead without Opportunity in Dynamics 365

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 Demo

Adhoc 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.

Read more: Dynamics 365 API: Invoke Process Action for Global Actions

Plugin Code:

The plugin code mentioned below would not create an opportunity, account, or contact:

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 Demo

Conclusion

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

Infographics show the 2021 MSUS Partner Award winner

Related Posts

Receive Updates on Youtube

6 thoughts on “Qualify Lead without Opportunity in Microsoft Dynamics CRM using C#”

  1. I’m trying to implement your solution in our CRM. First, I create the plugin on the Lead entity on the Qualify message but the plugin was not fired, so I change the configuration to the update message and the result was good; In my case I need to create only a contact and an account without the opportunity. Server side no problem, but the client side JavaScript code does work for me or I did not understood haw I must use it. You said that I need to put the JavaScript code on the Onload of the Lead. I did it but the result was that the form keep reloading all the time in a loop!!! without opening the contact form.

    Thanks for you help

  2. @HEDI

    Can you debug the value of SaveMode variable as I think reloading issue occurs when the check failed related to SaveMode.

  3. Hey BOLDENTHUSIAST, this is really great functionality, thanks! I’ve been looking for something like this for some time now and didn’t find a working solution until now. Only problem I encounter is a ” Reference error: function is not defined at eval.” message on the form load, which I can’t solve. Now I’m not an expert in javascript, so I’m hoping this is something that is easily solved. Any Ideas on this?

    Thanks again!

  4. Hi BOLDENTHUSIAST, thanks for you reply! The reference error is luckily not showing anymore. But now I encounter the same issue as HEDI, the form keeps refresh continuously. How can I debug the value of SaveMode, as you suggested to HEDI above? Thanks again!!

  5. Hi Tim,

    As you know that Debugging requires collective effort, I would suggest that you drop us an email at [email protected] with all the relevant details. We will come up with a way to help you by scheduling a meeting or a session with a technical consultant.

Comments are closed.