Skip to main content

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

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

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

// Your code
}

 


Hi ​@hotdok,

Please check This post as well.

 


 


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

 


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


Some additional information would be helpful.


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

 


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


Reply