Solved

Retreive value from one DAC and use it in another

  • 1 December 2021
  • 10 replies
  • 82 views

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.

icon

Best answer by Naveen Boga 1 December 2021, 09:21

View original

10 replies

Userlevel 6
Badge +5

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)  
Userlevel 7
Badge +12

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> { }
Userlevel 6
Badge +5

Hi @Naveen B Thats a quick and great code.

@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);
}

 

Userlevel 7
Badge +12

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

 

 

 

 

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'.
 
Userlevel 7
Badge +12

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

Userlevel 7
Badge +12

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

 

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?

 

Userlevel 7
Badge +12

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

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2022  Acumatica, Inc. All rights reserved