Skip to main content
Solved

How can we override convert to opportunity action in lead


Forum|alt.badge.img

How can we override convert to opportunity action in lead. because when convert I want to copy some data to opportunity.

Best answer by andriitkachenko

Hi @vannakheng66 

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.

View original
Did this topic help you find an answer to your question?

5 replies

Forum|alt.badge.img+7
  • Captain II
  • 295 replies
  • June 6, 2024

Hi @vannakheng66,

 

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.


Nilkanth Dipak
Jr Varsity III
Forum|alt.badge.img+7

Hi @vannakheng66 ,

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) {

      }
  }

 


Forum|alt.badge.img
  • Author
  • Freshman II
  • 39 replies
  • June 7, 2024
Dipak Nilkanth wrote:

Hi @vannakheng66 ,

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
    }
}
   


Chris Hackett
Community Manager
Forum|alt.badge.img
  • Acumatica Community Manager
  • 2657 replies
  • July 25, 2024

Hi @vannakheng66 were you able to find a solution? Thank you!


andriitkachenko
Jr Varsity I
Forum|alt.badge.img+5

Hi @vannakheng66 

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


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings