Skip to main content
Answer

Trying to update custom field in POLine (Grid) of the Purchase Orders table AFTER PO number assigned

  • May 15, 2025
  • 3 replies
  • 52 views

Joe Schmucker
Captain II
Forum|alt.badge.img+3

I have a custom field UsrLotNumber in the POLine table.  I want to update that field to the PO Number.  Please don’t ask why the customer wants to do this…

The issue is that the PO Number is “<NEW>” until after you save the PO.

I put code in the RowPersisting handler of the POLine table.

However, the OrderNbr field is “<NEW>” at this point.  I tried putting the code in the POOrder rowpersisting, but it still doesn’t save to the DB.

This is my POOrderRowPersisting code.  It shows the value in the grid after saving, but no update to the DB.

protected void POOrder_RowPersisting(PXCache cache, PXRowPersistingEventArgs e)
{
var row = (POOrder)e.Row;

foreach (POLine line in Base.Transactions.Select())
{
BSPOLineExt ext = line.GetExtension<BSPOLineExt>();
if (ext == null) return;

InventoryItem inventory = SelectFrom<InventoryItem>.Where<InventoryItem.inventoryID.IsEqual<@P.AsInt>>.View.Select(Base, line.InventoryID);
if (inventory == null) return;

INLotSerClass iNLotSerClass = SelectFrom<INLotSerClass>.Where<INLotSerClass.lotSerClassID.IsEqual<@P.AsString>>.View.Select(Base, inventory.LotSerClassID);
if (iNLotSerClass == null) return;

PXCache myCache = Base.Caches<POLine>();

if (row.OrderNbr.Trim() != "<NEW>")
{
if (iNLotSerClass.LotSerTrack == "L")
{
if (ext.UsrLotNumber == null)
{
myCache.SetValue<BSPOLineExt.usrLotNumber>(row, row.OrderNbr);
ext.UsrLotNumber = row.OrderNbr;
myCache.Update(line);
//myCache.Persist(PXDBOperation.Update);
//Base.Transactions.Update(line);
}
}
}
}
}

This is my code for the POLine rowpersisting, but the OrderNbr is “<NEW>” so it is not helpful.

protected void POLine_RowPersisting(PXCache cache, PXRowPersistingEventArgs e, PXRowPersisting InvokeBaseHandler)
{
if (InvokeBaseHandler != null)
InvokeBaseHandler(cache, e);
var row = (POLine)e.Row;


if (cache.GetStatus(row) == PXEntryStatus.Deleted) return;

BSPOLineExt ext = row.GetExtension<BSPOLineExt>();
if (ext == null) return;

InventoryItem inventory = SelectFrom<InventoryItem>.Where<InventoryItem.inventoryID.IsEqual<@P.AsInt>>.View.Select(Base, row.InventoryID);
if (inventory == null) return;

INLotSerClass iNLotSerClass = SelectFrom<INLotSerClass>.Where<INLotSerClass.lotSerClassID.IsEqual<@P.AsString>>.View.Select(Base, inventory.LotSerClassID);
if (iNLotSerClass == null) return;

if (row.OrderNbr.Trim() != "<NEW>")
{
if (iNLotSerClass.LotSerTrack == "L")
{
if (ext.UsrLotNumber == null)
{
ext.UsrLotNumber = row.OrderNbr;
cache.SetValue<BSPOLineExt.usrLotNumber>(row, row.OrderNbr);
cache.Update(row);
}
}
}

}

Any suggestions as to where to do the update to the custom field?

Best answer by Naveen Boga

Hi ​@Joe Schmucker  You are using the POLine.OrderNbr, instead POOrder.OrderNbr can you please try with the below and it should work.

 

  protected void POLine_RowPersisting(PXCache cache, PXRowPersistingEventArgs e, PXRowPersisting InvokeBaseHandler)
{
InvokeBaseHandler?.Invoke(cache, e);
POLine row = (POLine)e.Row;

if (row != null && Base.Document.Current != null)
{
if (cache.GetStatus(row) == PXEntryStatus.Deleted) return;

BSPOLineExt ext = row.GetExtension<BSPOLineExt>();
if (ext == null) return;

InventoryItem inventory = SelectFrom<InventoryItem>.Where<InventoryItem.inventoryID.IsEqual<@P.AsInt>>.View.Select(Base, row.InventoryID);
if (inventory == null) return;

INLotSerClass iNLotSerClass = SelectFrom<INLotSerClass>.Where<INLotSerClass.lotSerClassID.IsEqual<@P.AsString>>.View.Select(Base, inventory.LotSerClassID);
if (iNLotSerClass == null) return;

if (Base.Document.Current.OrderNbr.Trim() != "<NEW>")
{
if (iNLotSerClass.LotSerTrack == "L")
{
if (ext.UsrLotNumber == null)
{
ext.UsrLotNumber = Base.Document.Current.OrderNbr;
//cache.SetValue<BSPOLineExt.usrLotNumber>(row, row.OrderNbr);
cache.Update(row);
}
}
}
}
}

 

3 replies

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

Try this:

  1. override the Persist method
  2. call baseMethod to execute the initial persist
  3. update your field
  4. if I remember correctly, since your override is still persisting, you shouldn’t need to call save or anything

Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • Answer
  • May 16, 2025

Hi ​@Joe Schmucker  You are using the POLine.OrderNbr, instead POOrder.OrderNbr can you please try with the below and it should work.

 

  protected void POLine_RowPersisting(PXCache cache, PXRowPersistingEventArgs e, PXRowPersisting InvokeBaseHandler)
{
InvokeBaseHandler?.Invoke(cache, e);
POLine row = (POLine)e.Row;

if (row != null && Base.Document.Current != null)
{
if (cache.GetStatus(row) == PXEntryStatus.Deleted) return;

BSPOLineExt ext = row.GetExtension<BSPOLineExt>();
if (ext == null) return;

InventoryItem inventory = SelectFrom<InventoryItem>.Where<InventoryItem.inventoryID.IsEqual<@P.AsInt>>.View.Select(Base, row.InventoryID);
if (inventory == null) return;

INLotSerClass iNLotSerClass = SelectFrom<INLotSerClass>.Where<INLotSerClass.lotSerClassID.IsEqual<@P.AsString>>.View.Select(Base, inventory.LotSerClassID);
if (iNLotSerClass == null) return;

if (Base.Document.Current.OrderNbr.Trim() != "<NEW>")
{
if (iNLotSerClass.LotSerTrack == "L")
{
if (ext.UsrLotNumber == null)
{
ext.UsrLotNumber = Base.Document.Current.OrderNbr;
//cache.SetValue<BSPOLineExt.usrLotNumber>(row, row.OrderNbr);
cache.Update(row);
}
}
}
}
}

 


Joe Schmucker
Captain II
Forum|alt.badge.img+3
  • Author
  • Captain II
  • May 16, 2025

@darylbowman Thank you for the tip.  However, I went with ​@Naveen Boga ‘s fix as I already had all the code written.

Naveen, that did the trick.  The dangers of copy/paste!

I also removed the cache.Update(row): as it wasn’t needed.