Thanks @darylbowman for the suggestions. I also tried the row inserted event handler for this and it works as well. Is the method used below correct?
//ADD ROWINSERTED LOGIC
protected virtual void _(Events.RowInserted<AMProdItem> e)
{
UpdateChildOrder(e.Cache, e.Row);
}
protected virtual void _(Events.RowUpdated<AMProdItem> e)
{
UpdateChildOrder(e.Cache, e.Row);
}
private void UpdateChildOrder(PXCache cache, AMProdItem row)
{
if (row == null || cache == null)
return;
// Ensure this is a child order with a valid parent
if (string.IsNullOrEmpty(row.ParentOrdID))
return;
// Query the parent order using PK.Find
var parentOrder = AMProdItem.PK.Find(Base, row.ParentOrderType, row.ParentOrdID);
if (parentOrder == null)
return;
// Update the child order fields using parent order values
cache.SetValueExt<AMProdItem.qtytoProd>(row, parentOrder.QtytoProd);
if (!string.IsNullOrEmpty(parentOrder.BOMRevisionID))
{
cache.SetValueExt<AMProdItem.bOMRevisionID>(row, parentOrder.BOMRevisionID);
}
PXTrace.WriteInformation($"Child order updated: {row.ProdOrdID}, Parent: {parentOrder.ProdOrdID}, QtyToProd: {row.QtytoProd}");
}
//END OF ROW INSERTED LOGIC