Skip to main content
Answer

How to save dac inside row persisted event?

  • January 6, 2025
  • 8 replies
  • 200 views

Forum|alt.badge.img+1

Hi,

Im  trying to save some extra data to database on RowPersisted event. If Im using Base.Save.Press(); as I did in actions then my code runs into infinite recursion. So is there any way I can do without running into infinite recursion. Im saving extra data on RowPersisted event because some data have to be saved when new record is created. If there is other ways to do it outside the RowPersisted event then it would be great!

Tried to use RowInserted event but ShipmentNbr is not populated there so it is useless

Best answer by hotdok

ok I finally figured it out. We need to use RowPersisted event because only in this event all shipment values are already available. Then in order to save data in db we need to user PXDatabase object instead of Base.Save();
 

protected void SOShipment_RowPersisted(PXCache cache, PXRowPersistedEventArgs e)
{
// check if insert operation
if(e.Operation == PXDBOperation.Insert) {
// updating data in database
PXDatabase.Update<Obj>(
new PXDataFieldAssign<Obj.Val>(someval),
new PXDataFieldRestrict<Obj.Key>(PXDbType.Int, keyVal));
}
}

 

8 replies

darylbowman
Captain II
Forum|alt.badge.img+15

Instead of using RowPersisted, override the Persist event. Changes will be saved automatically:

protected override void Persist()
{
base.Persist();

// Your code
}

 


DipakNilkanth
Pro III
Forum|alt.badge.img+13

Hi ​@hotdok,

Please check This post as well.

 


Forum|alt.badge.img+1
  • Author
  • Varsity I
  • January 6, 2025

 


darylbowman
Captain II
Forum|alt.badge.img+15

If it’s in a graph extension, I believe it needs to look like this:

public delegate void PersistDelegate();
[PXOverride]
public void Persist(PersistDelegate baseMethod)
{
baseMethod();
}

 


Forum|alt.badge.img+1
  • Author
  • Varsity I
  • January 11, 2025

Thanks. That both suggestions are workable solutions in general I have problem that ShipmentNbr is not set. Thus it doesn’t work for me.


darylbowman
Captain II
Forum|alt.badge.img+15

Some additional information would be helpful.


Forum|alt.badge.img+1
  • Author
  • Varsity I
  • Answer
  • January 21, 2025

ok I finally figured it out. We need to use RowPersisted event because only in this event all shipment values are already available. Then in order to save data in db we need to user PXDatabase object instead of Base.Save();
 

protected void SOShipment_RowPersisted(PXCache cache, PXRowPersistedEventArgs e)
{
// check if insert operation
if(e.Operation == PXDBOperation.Insert) {
// updating data in database
PXDatabase.Update<Obj>(
new PXDataFieldAssign<Obj.Val>(someval),
new PXDataFieldRestrict<Obj.Key>(PXDbType.Int, keyVal));
}
}

 


Chris Hackett
Community Manager
Forum|alt.badge.img
  • Acumatica Community Manager
  • January 21, 2025

Thank you for sharing your solution with the community ​@hotdok!