Follow my blog for more interesting topics on Dynamics 365, Portals and Power Platform. For training and consulting, write to us at info@xrmforyou.com
CRM tips from the vault – A series which I have started on request of my blog readers who are quite new to CRM. My blog focus on niche topics which mostly require a prior in-depth understanding of Dynamics 365. However in this series I will mostly cover the topics which are quite simple, used in almost every project implementations and more importantly have withstood the test of time.
Here is my Tip 2 – How to skip Account/ Contact/ Opportunity creation during Lead Qualification in Dynamics 365
In Dynamics 365, the Lead entity is designed to track potential clients. And the default behavior is when a lead is qualified, it creates an opportunity, contact and account record. However what if you don’t want to skip creating an account or contact or even opportunity when you qualify a lead?
You may be wondering, after all lead converts to Opportunity. That is the default behavior. But again every business is different. For example – For some business, the moment a lead gets qualified to a customer, it is a confirmed business for your client. In that case you don’t need to again go through the Opportunity cycle.
So now we understand the requirement. But how to accomplish this requirement. Well there are couple of ways. Let’s explore them.
Option 1 – Change Qualify Lead Experience to provide user option to create Account/ Contact/ Opportunity.
This one is pretty simple. All we need is to change the Qualify experience option in Dynamics 365.
For that navigate to Settings –> Administration –> System Settings and navigate to Sales tab.
Check for “Qualify lead experience” option. The default behavior is to automatically create a contact/ account and opportunity when a lead is qualified. Set this value to “No”. And save the settings.
Now when you Qualify the lead, the user will be presented with the below popup.
Here the user can choose to create a contact/ account or opportunity depending on business requirement.
Option 2 : Register a plugin on lead pre-qualify step
While changing the lead qualification experience using System settings is pretty simple option, it’s not flexible. For example – Based on some business calculation you want to take a decision whether to create a contact/ account or opportunity. You don’t have an option to do that using the Qualify lead experience. In cases like this, you need to handle it through plugins.
For this register a plugin on Pre-operation stage of QualifyLead message.
And below is a sample code on how to handle the creation of contact/ account or opportunity.
public class PreOperationQualifyLead :IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
var context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
var orgFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
var orgService = (IOrganizationService)orgFactory.CreateOrganizationService(context.InitiatingUserId);
//take the input parameters
var isCreateAccount = (bool)context.InputParameters["CreateAccount"];
var isCreateContact = (bool)context.InputParameters["CreateContact"];
var isCreateOpportunity = (bool)context.InputParameters["CreateOpportunity"];
var status = (Int32)context.InputParameters["Status"]; //3
var leadEntRef = (EntityReference)context.InputParameters["Target"];
// add custom logic say and determine if you want to create a contact/ account or opportunity.
// the below code will skip contact creation during Qualify process.
context.InputParameters["CreateContact"] = false;
}
}
The plugin step will also take care of situations when a lead is qualified programmatically and not through UI.
Hope this helps!
Debajit Dutta
(Microsoft MVP)
Discover more from Debajit's Power Apps & Dynamics 365 Blog
Subscribe to get the latest posts sent to your email.