Skip to main content
Solved

Retreive value from one DAC and use it in another


Good day,

I have created a new custom field named transport on the opportunities, sales quote, sales order and invoices and memo’s screen.
I would like the value entered in the custom field to carry over to the sales quote, sales order and invoices and memo screen when a new one is created.

Currently the value already carries over to sales quotes, since it uses the same DAC as opportunities.

Any help on how to be able to achieve this would be great.

Best answer by Naveen Boga

Hi @charlbester34  Please find the code  below. I not seeing that issue anymore.

 

  public PXAction<CROpportunity> createSalesOrder;
        [PXUIField(DisplayName = Messages.CreateSalesOrder, MapEnableRights = PXCacheRights.Update, MapViewRights = PXCacheRights.Select)]
        [PXButton]
        public virtual IEnumerable CreateSalesOrder(PXAdapter adapter)
        {
            PXGraph.InstanceCreated.AddHandler<SOOrderEntry>((graph) =>
            {
                graph.RowInserted.AddHandler<SOLine>((cache, args) =>
                {
                    var soOrderLine = (SOLine)args.Row;

                    KNSOLineExt soOrderLineExt = soOrderLine.GetExtension<KNSOLineExt>();

                    foreach (CROpportunityProducts line in Base.Products.Select().FirstTableItems.ToList().Where(x=>x.InventoryID == soOrderLine.InventoryID))
                    {

                        CROpportunityProductsExt lineExt = line.GetExtension<CROpportunityProductsExt>();

                        soOrderLineExt.UsrTransport = lineExt.UsrTransport;
                        graph.Transactions.Cache.Update(soOrderLine);

                    }
                });
            });
            return Base.createSalesOrder.Press(adapter);
        }

 

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

10 replies

Forum|alt.badge.img+8
  • Semi-Pro I
  • 715 replies
  • December 1, 2021

Hi @charlbester34 Please try using the Row_inserted event on each screens (SalesOrder, ARInvoice) to have the value populated on the custom screen.

For Instance on the Sales order Screen:

  1. Create a BQL view with the JOIN on the SalesOrder and Sales Quote/Opportunity to get the Custom value.
  2. Assign the Value to the Customer(usr field)  

Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • 3410 replies
  • December 1, 2021

Hi @charlbester34    We can achieve your requirement using [PXDefault()] attribute. 

Below is the sample code for your reference to get the value from Opportunities to Sales Quote and the same way you can use it for other screens.

 

Hope this helps!

// The below code will get the value from Opportunity to Sales Quote 

public sealed class SalesQuoteExt : PXCacheExtension<SalesQuote>
    {
        #region UsrCustomField

        [PXDBDecimal()]
        [PXDefault(typeof(Search<OpportunityExt.CustomField,
                Where<Opportunity.Condition1, Equal<Current<SalesQuote.Condition1>>,
                And<Opportunity.Condition2, Equal<Current<SalesQuote.Condition2>>,
                And<Opportunity.Condition3, Equal<Current<SalesQuote.Condition3>>>>>>),
        PersistingCheck = PXPersistingCheck.Nothing)]
        [PXUIField(DisplayName = "Transaction")]
        public virtual decimal? UsrCustomField { get; set; }
        public abstract class usrCustomField : PX.Data.BQL.BqlDecimal.Field<usrCustomField> { }

Forum|alt.badge.img+8
  • Semi-Pro I
  • 715 replies
  • December 1, 2021

Hi @Naveen B Thats a quick and great code.


  • Author
  • Freshman I
  • 6 replies
  • December 1, 2021

@Naveen B@ChandrasekharM 

Currently I am working with the following code, but I am getting the following error when trying to create the sales order

 

Unable to cast object of type 'PX.Data.PXResult`2[PX.Objects.CR.CROpportunity,PX.Objects.CR.BAccount]' to type 'PX.Objects.CR.CROpportunityProductsExt'.
 
 public PXAction<CROpportunity> createSalesOrder;
        [PXUIField(DisplayName = Messages.CreateSalesOrder, MapEnableRights = PXCacheRights.Update, MapViewRights = PXCacheRights.Select)]
        [PXButton(ImageKey = PX.Web.UI.Sprite.Main.DataEntry)]
        public virtual IEnumerable CreateSalesOrder(PXAdapter adapter)
        {
            PXGraph.InstanceCreated.AddHandler<SOOrderEntry>((graph) =>
            {
                graph.RowInserted.AddHandler<SOLine>((cache, args) =>
                {
                    var soOrderLine = (SOLine)args.Row;
                    var soOrderLineExt = PXCache<SOLine>.GetExtension<SOLineExt>(soOrderLine);


                    foreach (CROpportunityProductsExt line in adapter.Get())
                    {
                        soOrderLineExt.UsrTransport = line.UsrTransport;
                    }
                });
            });
            return Base.createSalesOrder.Press(adapter);
        }

 


Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • 3410 replies
  • December 1, 2021

Hi @charlbester34  Please try with below code

public PXAction<CROpportunity> createSalesOrder;
        [PXUIField(DisplayName = Messages.CreateSalesOrder, MapEnableRights = PXCacheRights.Update, MapViewRights = PXCacheRights.Select)]
        [PXButton(ImageKey = PX.Web.UI.Sprite.Main.DataEntry)]
        public virtual IEnumerable CreateSalesOrder(PXAdapter adapter)
        {
            PXGraph.InstanceCreated.AddHandler<SOOrderEntry>((graph) =>
            {
                graph.RowInserted.AddHandler<SOLine>((cache, args) =>
                {
                    var soOrderLine = (SOLine)args.Row;
                    var soOrderLineExt = PXCache<SOLine>.GetExtension<SOLineExt>(soOrderLine);


                    foreach (CROpportunityProducts line in adapter.Get())
                    {
					   CROpportunityProductsExt lineExt = line.GetExtension<CROpportunityProductsExt>();

                        soOrderLineExt.UsrTransport = lineExt.UsrTransport;
                    }
                });
            });
            return Base.createSalesOrder.Press(adapter);
        }

 

Below code changes I have done for CROpportunityProductsExt. Please verify

 

 

 

 


  • Author
  • Freshman I
  • 6 replies
  • December 1, 2021

Hi @Naveen B, I have tested it and It is still providing me with an error:
 

Unable to cast object of type 'PX.Data.PXResult`2[PX.Objects.CR.CROpportunity,PX.Objects.CR.BAccount]' to type 'PX.Objects.CR.CROpportunityProducts'.
 

Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • 3410 replies
  • December 1, 2021

@charlbester34  Okay, will check this and let you know.


Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • 3410 replies
  • Answer
  • December 1, 2021

Hi @charlbester34  Please find the code  below. I not seeing that issue anymore.

 

  public PXAction<CROpportunity> createSalesOrder;
        [PXUIField(DisplayName = Messages.CreateSalesOrder, MapEnableRights = PXCacheRights.Update, MapViewRights = PXCacheRights.Select)]
        [PXButton]
        public virtual IEnumerable CreateSalesOrder(PXAdapter adapter)
        {
            PXGraph.InstanceCreated.AddHandler<SOOrderEntry>((graph) =>
            {
                graph.RowInserted.AddHandler<SOLine>((cache, args) =>
                {
                    var soOrderLine = (SOLine)args.Row;

                    KNSOLineExt soOrderLineExt = soOrderLine.GetExtension<KNSOLineExt>();

                    foreach (CROpportunityProducts line in Base.Products.Select().FirstTableItems.ToList().Where(x=>x.InventoryID == soOrderLine.InventoryID))
                    {

                        CROpportunityProductsExt lineExt = line.GetExtension<CROpportunityProductsExt>();

                        soOrderLineExt.UsrTransport = lineExt.UsrTransport;
                        graph.Transactions.Cache.Update(soOrderLine);

                    }
                });
            });
            return Base.createSalesOrder.Press(adapter);
        }

 


  • Author
  • Freshman I
  • 6 replies
  • December 1, 2021

Hi @Naveen B

Thank you for this, It definitely solved my issue regarding my error, but for some reason the transport value does not carry over.

Do you also experience this?

 


Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • 3410 replies
  • December 1, 2021

@charlbester34   Yes, did  you debug the code and getting the value from CROpportunityProductsExt transport value?


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