How can we override convert to opportunity action in lead. because when convert I want to copy some data to opportunity.
How can we override convert to opportunity action in lead
Hi
You will have to create a graph extension to override the action, it will look somethig like this:
public class QuoteMaintExt : PXGraphExtension<QuoteMaint.CRCreateSalesOrderExt, QuoteMaint>
{
public static bool IsActive() => true;
[PXOverride]
public IEnumerable createSalesOrder(PXAdapter adapter, Func<PXAdapter, IEnumerable> baseMethod)
{
PXGraph.InstanceCreated.AddHandler(delegate (SOOrderEntry graph)
{}}}
This is for creating a sales order but i believe the process will be similar to override creating a opportunity.
Hi
You can use below code snippet to override the Convert To Opportunity action. use “public virtual void DoConvert(bool redirect)” method to send your values. I have not validated it, but you can give it a try.
public class CreateOpportunityAllFromLeadGraphExt : CRCreateOpportunityAllAction<LeadMaint, CRLead, LeadMaint.CreateOpportunityFromLeadGraphExt, LeadMaint.CreateAccountFromLeadGraphExt, LeadMaint.CreateContactFromLeadGraphExt>
{
public static bool IsActive() => true;
public override void DoConvert(bool redirect) {
}
}
Hi
You can use below code snippet to override the Convert To Opportunity action. use “public virtual void DoConvert(bool redirect)” method to send your values. I have not validated it, but you can give it a try.
public class CreateOpportunityAllFromLeadGraphExt : CRCreateOpportunityAllAction<LeadMaint, CRLead, LeadMaint.CreateOpportunityFromLeadGraphExt, LeadMaint.CreateAccountFromLeadGraphExt, LeadMaint.CreateContactFromLeadGraphExt>
{
public static bool IsActive() => true;
public override void DoConvert(bool redirect) {
}
}
It is running override block of code I try to insert some data of opportunity in rowinsert event but cannot insert in opportunity. Is it the event row inserted properly trigger or where else.
namespace PX.Objects.CR
{
// Acuminator disable once PX1016 ExtensionDoesNotDeclareIsActiveMethod extension should be constantly active
public class CreateOpportunityAllFromLeadGraphExt_Extension : CRCreateOpportunityAllAction<LeadMaint, CRLead, LeadMaint.CreateOpportunityFromLeadGraphExt, LeadMaint.CreateAccountFromLeadGraphExt, LeadMaint.CreateContactFromLeadGraphExt>
{
#region Event Handlers
public override void DoConvert(bool redirect)
{
PXGraph.InstanceCreated.AddHandler<OpportunityMaint>((graph) =>
{
graph.RowInserted.AddHandler<CROpportunity>((sender, e) =>
{
CROpportunity cROpportunity = e.Row as CROpportunity;
ContactExt contactExt = PXCache<Contact>.GetExtension<ContactExt>(Base.Lead.Current);
CROpportunityExt cROpportunityExt = PXCache<CROpportunity>.GetExtension<CROpportunityExt>(cROpportunity);
cROpportunityExt.UsrExtArea = contactExt.UsrExtArea;
cROpportunityExt.UsrProjectProgress = contactExt.UsrProjectProgress;
cROpportunityExt.UsrIntArea = contactExt.UsrIntArea;
cROpportunityExt.UsrInstructor = contactExt.UsrInstructor;
cROpportunityExt.UsrTotalArea = contactExt.UsrTotalArea;
});
});
base.DoConvert(redirect);
}
#endregion
}
}
Hi
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.