Old Qualify Lead Dialog in CRM 2011
We had a dialog box in Microsoft CRM 2011 which we used to create Account, Contact and Opportunity in Lead Qualification process.
Learn more about our Microsoft Dynamics 365 Services 
But this dialog box is deprecated, and we do not have this dialog box in Dynamic 365 Sales anymore.
Qualify Lead in Dynamics 365 Sales
Now inside the lead form in CRM there are two fields named as “Existing Contact” and “Existing Account”, and we use these fields to add related Contact or Account.
Adhoc Lead Qualify Process
This is very useful design to optimize flow based on business requirements. If a record already exists, system uses it to associate qualified lead rather than creating a new one. However, it depends on how you implement it and what the business requirements are. Sometimes we don’t want to create new opportunity as part of the lead qualification process. In addition, we also need lead qualification without account or contact creation at times. Moreover, at times in case the implementation is using xRM as a platform, business requirements might govern 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 lead without creating opportunity, account or contact.
Plugin Code
Plugin code mentioned below would not create 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 ‘QualifyLead’ Message at ‘Pre-Operation’.
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 below JS on “onload” event of 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 and all-together they work fine in the background.
Hope this will be helpful.
Thanks!!!
Explore our Microsoft Dynamics 365 Services 
Conclusion
So, we can avoid 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 Lead Page.
If you have any question or queries, do not hesitate to reach out to us!Â
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
@HEDI
Can you debug the value of SaveMode variable as I think reloading issue occurs when the check failed related to SaveMode.
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!
@TIM
We are not using eval function in js. I think you need to look at your JS code and see if there is any utilization of this function.
If you have any further questions or queries, feel free to drop an email at [email protected].
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!!
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.