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?