How can we override convert to opportunity action in lead. because when convert I want to copy some data to opportunity.
Solved
How can we override convert to opportunity action in lead
Best answer by andriitkachenko
As far as I can see, Acumatica already has an extension CreateOpportunityFromLeadGraphExt
.
I suppose you want to provide your additional values from Contact
and leave the rest intact.
CreateOpportunityFromLeadGraphExt
uses OpportunityMaint
to create CROpportunity
record.
I’d suggest trying to create a customization for the OpportunityMaint
and try to add your values there:
// Acuminator disable once PX1016 ExtensionDoesNotDeclareIsActiveMethod extension should be constantly active
public class OpportunityMaintExtension : PXGraphExtension<OpportunityMaint>
{
public virtual void _(Events.RowInserted<CROpportunity> e)
{
if (!(e.Row is CROpportunity row)) return;
var contactExt = Base.Contacts.Current.GetExtension<ContactExt>();
var cROpportunityExt = row.GetExtension<CROpportunityExt>();
cROpportunityExt.UsrExtArea = contactExt.UsrExtArea;
cROpportunityExt.UsrProjectProgress = contactExt.UsrProjectProgress;
cROpportunityExt.UsrIntArea = contactExt.UsrIntArea;
cROpportunityExt.UsrInstructor = contactExt.UsrInstructor;
cROpportunityExt.UsrTotalArea = contactExt.UsrTotalArea;
}
}
If that doesn’t help, here’s another thing to try:
// Acuminator disable once PX1016 ExtensionDoesNotDeclareIsActiveMethod extension should be constantly active
public class OverrideCreateMasterExt : PXGraphExtension<CreateOpportunityFromLeadGraphExt, LeadMaint>
{
public delegate CROpportunity CreateMasterDelegate(OpportunityMaint graph, OpportunityConversionOptions options);
[PXOverride]
public virtual CROpportunity CreateMaster(OpportunityMaint graph, OpportunityConversionOptions options, CreateMasterDelegate baseMethod)
{
var opportunity = baseMethod(graph, options);
var contactExt = graph.Contacts.Current.GetExtension<ContactExt>();
var cROpportunityExt = opportunity.GetExtension<CROpportunityExt>();
cROpportunityExt.UsrExtArea = contactExt.UsrExtArea;
cROpportunityExt.UsrProjectProgress = contactExt.UsrProjectProgress;
cROpportunityExt.UsrIntArea = contactExt.UsrIntArea;
cROpportunityExt.UsrInstructor = contactExt.UsrInstructor;
cROpportunityExt.UsrTotalArea = contactExt.UsrTotalArea;
return opportunity;
}
}
[PXProtectedAccess]
public abstract class ExposeCreateMasterExt : PXGraphExtension<OverrideCreateMasterExt, LeadMaint>
{
[PXProtectedAccess(typeof(POCreate))]
protected abstract CROpportunity CreateMaster(OpportunityMaint graph, OpportunityConversionOptions options);
}
I’d also double-check if Base.Contacts.Current
/graph.Contacts.Current
will yield expected results - you might need to make additional logic to retrieve the correct Contact
record.
Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.