we had a similar requirements in the past, the idea is to drive the creation of Opportunity/Account/Contact based on your customer requirement
our solution was a Plugin prequalify (if a parentaccount is prefill do not create an additional account,, if a contact is prefill get the contact parent account and do not create neither account and contact for example), get the user the chance to decide if you want to create an opportunity or not
the code is not well formatted (I am sorry for that :(:(:(:( )
public class LeadPreQualifyDriveopportunityContactAccountCreation : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
IOrganizationService _organizationService; ITracingService _tracingService;
_tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
_tracingService.Trace("Plugin 'LeadPreQualifyDriveopportunityContactAccountCreation' has been called. ");
//if (serviceProvider is null) throw new ArgumentNullException(nameof(serviceProvider));
// Obtain the execution context from the service provider.
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
// Extract the tracing service for use in debugging sandboxed plug-ins.
// Obtain OrganizationServiceFactory and OrganizatíonSerive from serviceProvider
var factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
_organizationService = factory.CreateOrganizationService(context.UserId);
_tracingService.Trace($"IP{context.InputParameters.Count}");
_tracingService.Trace($"IPcontains{context.InputParameters.Contains("LeadId")}");
EntityReference leadReference = (EntityReference)context.InputParameters["LeadId"];
_tracingService.Trace($"ldid{leadReference.Id}");
var LeadEntity = _organizationService.Retrieve("lead", leadReference.Id, new ColumnSet("xyz_createopportunityoption", "parentcontactid", "parentaccountid"));
//xyz_createopportunityoption --> 765740001 No 765740000 Yes
OptionSetValue xyz_createopportunityoption = LeadEntity.GetAttributeValue<OptionSetValue>("xyz_createopportunityoption") != null ? LeadEntity.GetAttributeValue<OptionSetValue>("xyz_createopportunityoption") : null;
_tracingService.Trace($"opp {xyz_createopportunityoption.Value}");
EntityReference parentcontactid = LeadEntity.GetAttributeValue<EntityReference>("parentcontactid") != null ? LeadEntity.GetAttributeValue<EntityReference>("parentcontactid") : null;
_tracingService.Trace($"Pc not null {parentcontactid != null}");
EntityReference parentaccountid = LeadEntity.GetAttributeValue<EntityReference>("parentaccountid") != null ? LeadEntity.GetAttributeValue<EntityReference>("parentaccountid") : null;
_tracingService.Trace($"PA not null {parentaccountid != null}");
bool createOpp = false;
if (xyz_createopportunityoption!= null)
{
createOpp = xyz_createopportunityoption.Value == 765740001 ? false : true;
if(context.InputParameters.Contains("CreateOpportunity"))
{
context.InputParameters["CreateOpportunity"] = createOpp;
}
else
{
context.InputParameters.Add("CreateOpportunity", createOpp);
}
}
bool createCon = parentcontactid == null;
if (context.InputParameters.Contains("CreateContact"))
{
context.InputParameters["CreateContact"] = createCon;
}
else
{
context.InputParameters.Add("CreateContact", createCon);
}
bool createAcc = parentaccountid == null;
if (context.InputParameters.Contains("CreateAccount"))
{
context.InputParameters["CreateAccount"] = createAcc;
}
else
{
context.InputParameters.Add("CreateAccount", createAcc);
}
context.InputParameters.Add("SuppressDuplicateDetection ", false);
_tracingService.Trace($"CO {createOpp} CC {createCon} CA {createAcc}");
}
}
------------------------------
Giovanni manunta
Application Owner MS Dynamics 365 CE
------------------------------
Original Message:
Sent: Dec 15, 2022 04:46 PM
From: Autumn Hearne
Subject: Force Account/Contact Creation on Lead Qualification?
Not sure if this is a training issue or if it can be solved programmatically.
Our users have the option to create an Opportunity upon Lead qualification, which we want them to have. However, we have several users who change Account/Contact to No and Opportunity to Yes, and then an Opportunity is created without an Account, causing problems.
I have instructed users not to do this, but it happens at least once a week, often more.
Is there a way to prevent them from changing the Account/Contact options to No in the Lead Qualification popup? Or do I just need to be more diligent about training and correcting?
Thanks!
------------------------------
Autumn Hearne
Associate
Pinion Global (formerly KCoe Isom)
------------------------------