Asked by:
CRM 2013 plugin

Question
-
Hi All,
I have created the Lead record , Once we qualify it will automatically get create the contact/ account and Opportunity record rite it's OOB.
Once qualify record i don't want to create opportunity record .. i tried to disable the plug-in activity
Still opportunity records are getting created.. can you please suggest me on this..
Rammohan
Sunday, July 27, 2014 5:48 AM
All replies
-
Hi,
You'll need to write a Plugin and register it on PreValidation of QualifyLead message. In the Plugin code, you can stop creation of the Opportunity.
Have a look here, this blog article provides the code: http://developersintent.wordpress.com/2013/09/23/controlling-the-lead-qualification-process-in-crm-2013/
Sunday, July 27, 2014 8:10 AM -
Hi Dynamotion,
if (context.MessageName.ToLower() == "create")
{
entity = (Entity)context.InputParameters["Target"];
if (((OptionSetValue)context.InputParameters["Status"]).Value == 100000021) // status is lead qualification reason selected by the user.
{
context.InputParameters["CreateOpportunity"] = false; //set to true by default
context.InputParameters["CreateAccount"] = false; //set to true by default
entity = (Entity)context.PreEntityImages["PreImage"];
}
}i have followed the same code above forum.. anything i need add it?
can you please suggest me synamotion
Rammohan
Thursday, July 31, 2014 4:57 AM -
Hi
Can you refer the below link for preventing creation of opportunity
http://www.zero2ten.com/blog/processing-opportunities-created-after-qualifying-leads-on-the-new-user-experience-forms-in-microsoft-dynamics-crm/
Thursday, July 31, 2014 5:18 AM -
Hi Rammohan,
You need to register a plugin on qualifylead message(pre-operation). Try below code,
if (context.MessageName.ToLower() == "qualifylead")
{
if (((OptionSetValue)context.InputParameters["Status"]).Value == 100000021) // status is lead qualification reason selected by the user.
{
context.InputParameters["CreateOpportunity"] = false; //set to true by default
context.InputParameters["CreateAccount"] = false; //set to true by default
}
}HTH!
Thursday, July 31, 2014 5:41 AM -
just a note, the steps you disabled belong to the ActivityFeeds solution, they create the wall notifications when a contact or opportunity is created, they are not involved in the specific qualify lead process. It's better you enable them again.
You still need to write the plugin as already suggested.
My blog: www.crmanswers.net - Rockstar 365 Profile
Thursday, July 31, 2014 5:45 AM -
Hi I have used the above code and register the step under the qulifylead on pre operation only
Code:
public class LeadQualificationProcess : IPlugin
{
IOrganizationService service = null;
//[#Execute Mathod]public void Execute(IServiceProvider serviceProvider)
{
try
{
// #region Intialization of Service
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
service = factory.CreateOrganizationService(context.UserId);
// #endregion
Entity entity = null;
Guid grantId = Guid.Empty;
if (context.MessageName.ToLower() == "qualifylead")
{
if (((OptionSetValue)context.InputParameters["Status"]).Value == 100000021) // status is lead qualification reason selected by the user.
{
context.InputParameters["CreateOpportunity"] = false; //set to true by default
context.InputParameters["CreateAccount"] = false; //set to true by default}
}
}catch (Exception ex)
{
throw new InvalidPluginExecutionException(ex.Message);
}
}}
}still opportunity records are getting created..
can you please suggest me on this..
Rammohan
- Edited by Rammohan Ammiti Thursday, July 31, 2014 6:13 AM modified
Thursday, July 31, 2014 6:12 AM -
Hi Rammohan,
I have tried the same code on my test org and it worked. Please recheck the value of "Status"
Note: The Status property corresponds to the Lead.StatusCode attribute of the Lead entity.
public class LeadQualificationProcess : IPlugin
{
IOrganizationService service = null;
//[#Execute Mathod]
public void Execute(IServiceProvider serviceProvider)
{
try
{
// #region Intialization of Service
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
service = factory.CreateOrganizationService(context.UserId);
// #endregion
Entity entity = null;
Guid grantId = Guid.Empty;
if (context.MessageName.ToLower() == "qualifylead")
{
if (((OptionSetValue)context.InputParameters["Status"]).Value == 100000000) // status is lead qualification reason selected by the user.
{
context.InputParameters["CreateOpportunity"] = false; //set to true by default
context.InputParameters["CreateAccount"] = false; //set to true by default
}
}
}
catch (Exception ex)
{
throw new InvalidPluginExecutionException(ex.Message);
}
}
}HTH!
Thursday, July 31, 2014 7:02 AM -
Hi ,
I tried with
if (((OptionSetValue)context.InputParameters["Status"]).Value == 100000000)
code also .. opportunities are getting created..
I am using on premiss appliaction
I had checked with database
select StatusCode from lead
select statuscode,statuscodename, * from FilteredLeadstatuscode=3
even tried with 3 also not working...
Rammohan
Thursday, July 31, 2014 10:14 AM -
Hi Rammohan,
In code, I have used "100000000" because I have added new option "test" in the status reason field and its associated numeric value is "100000000".
While qualifying the lead I am selecting the status as test.
Please reconfirm the status code value.
HTH!
- Edited by DynaDeveloper Thursday, July 31, 2014 10:45 AM
Thursday, July 31, 2014 10:32 AM -
Hi Dyna,
The above code working fine.. after qualify the Lead record it's not moving Qulify stage immediately
it's still showing the Qulify button.. afte refreshing the page then only it's moving to Qulifed stage..
can you please guide me how can i achieve this..
Rammohan
Wednesday, August 6, 2014 1:40 PM