Question

How to get old value in one field ?

  • 15 September 2021
  • 5 replies
  • 20 views

Hi, i have some problem to get value from old value data, anyone have an idea ?
 

example, new SO have qty = 65 after save user edited value qty in SO become 50. i want to get value qty SO =  65.

or, how to implement query limit = 1 in acumatica ?


5 replies

Userlevel 6
Badge +9

Hi @yanuaralfianus37  Question: how to implement query limit = 1 in acumatica

Which means, you wanted to fetch only records using query just like below ?

Select Top (1) * from SOOrder 

 

Question: example, new SO have qty = 65 after save user edited value qty in SO become 50. i want to get value qty SO =  65.

You can see the old values in Sales Orders Audit History screen

 

Hi @Naveen B thanks for reply. 

yes that’s right, i want is to get old value qty in SOOrder, and i do compare with the new one qty in SOOrder (old and new value qty is in one order number).

Userlevel 6
Badge +9

Hi @yanuaralfianus37  We can get the old values in below 2 ways.

  • Row Level  → Use RowUdated Event
  • Field Level → Use FieldUpdated Event

Please find the sample code for your reference. 

 

protected virtual void SOLine_OrderQty_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
{
SOLine row = e.Row as SOLine;
if (row != null)
{

if (row.OrderQty != Convert.ToDecimal(e.OldValue))
{
// Add Logic
}
else
{
// Add Logic
}
}
}


protected virtual void SOLine_RowUpdated(PXCache cache, PXRowUpdatedEventArgs e, PXRowUpdated InvokeBaseHandler)
{
InvokeBaseHandler?.Invoke(cache, e);
SOLine newRow = e.Row as SOLine;
if (newRow != null)
{
SOLine oldRow = (SOLine)e.OldRow;
if (newRow.OrderQty != oldRow.OrderQty)
{
// Add Logic
}
else
{
//Add Logic
}
}
}

hi @Naveen B thanks for reply. i want to ask, how to that old value (before edit/update) save in new variable and i used it in RowPersisting event handler ? or how to trigger save in event handler RowUpdate / FieldUpdated so i can create error message ?

Userlevel 6
Badge +9

Hi @yanuaralfianus37 I think you can not the get the old values in RowPersisting Event and you can not invoke the SAVE action from event handler for this Acuminator will show us the PX1043 - Changes cannot be saved to the database from event handlers.

 

You can compare the OLD and NEW values in the FiledUpdated/RowUpdated event and throw an error message according to your logic.

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