Solved

PXDefault Value Based on Related Record Is not Populating

  • 25 October 2022
  • 5 replies
  • 80 views

Userlevel 2
Badge

I have a custom field on the customers screen for biller/billing nbr.  I want to default that onto the sales orders screen when the customer value is updated.  I attached my current code to add biller/billing nbr onto the customers screen and sales orders screen.  Right now, I had attempted to reset the default value on the sales orders screen when the location was updated, but it still isn’t populating.  What am I missing within the code to populate the custom field?

icon

Best answer by Naveen Boga 25 October 2022, 11:49

View original

5 replies

Userlevel 7
Badge +17

Hi @wojtysiaks  Have you provided the UsrBillingNbr field value in the Customer Location ID field in the Sales Order screen and are able to save the Sales Order manually?

 

Userlevel 5
Badge +2

@wojtysiaks as an alternative, you can retrieve the value from the master record and assign it to the cache in the FieldUpdated event. 
See the reference below:

    protected void SOOrder_CustomerID_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
{
if (e.Row == null) return;
var row = (SOOrder)e.Row;

BAccount customerRow = BAccount.PK.Find(Base, (int)row.CustomerID);
BAccountExt customerRowExt = customerRow.GetExtension<BAccountExt >();
SOOrderExt orderRowExt = row.GetExtension<SOOrderExt>();

orderRowExt.UsrBillerNbr = customerRowExt.UsrBillingNbr;
}

Notice that I moved the logic from CustomerLocationID to CustomerID as your field is found in that master table.

 

Attached is the updated customization package for your reference.

Userlevel 7
Badge +17

Hi @wojtysiaks  Sorry, I thought that you need to assign the UsrBillingNbr to the CustomerLocationID field in the Sales Order. Sorry for that.

 

I just reviewed and the above code should work as provided by @Fernando Amadoz but the code is missed to invoke the Base call, due to this which may lead to other issues in the future. 

Below is the updated code and customization package.

 

Hope this helps!

   protected void SOOrder_CustomerID_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e, PXFieldUpdated InvokeBaseHandler)
{
InvokeBaseHandler?.Invoke(cache, e);
if (e.Row == null) return;
var row = (SOOrder)e.Row;

BAccount customerRow = BAccount.PK.Find(Base, (int)row.CustomerID);
BAccountExt customerRowExt = customerRow.GetExtension<BAccountExt>();
SOOrderExt orderRowExt = row.GetExtension<SOOrderExt>();

orderRowExt.UsrBillerNbr = customerRowExt.UsrBillingNbr;
}

 

 

Userlevel 2
Badge

Thank you @Naveen Boga and @Fernando Amadoz !  This works perfect for my use case.  Your comments have been extremely helpful as well!

Userlevel 5
Badge +2

@Naveen Boga @wojtysiaks 

invoking the base handler is only needed if the third parameter is used in the event handler implementation.

Requires invoking base handler:

SOOrder_CustomerID_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e, PXFieldUpdated InvokeBaseHandler) 

Does not require to invoke it. The framework runs it as an additional layer to the base event:

SOOrder_CustomerID_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)

 

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 — 2024  Acumatica, Inc. All rights reserved