I have a header/line structure on a screen that needs to allow a lot of flexibility when entering data but prevent taking the record off hold until all line items have an inventory id. At the time the record is created, an inventory id may not exist, so I can't make the inventory id field required at initial entry.
I expected that PXSelect would pull any new records from the database but hold onto the currently cached data from entry. What I found instead was that entry of a new line item does not appear to be accessed via the PXSelect until I save the record. That means unchecking Hold ignores the inventory ID that I see on-screen, and the code below gives generates the exception for "NoInventoryID".
#region MyHdr_Hold_FieldVerifying
protected virtual void _(Events.FieldVerifying<MyHdr.hold> e)
{
if ((bool?)e.NewValue == true) return;
MyHdr row = (MyHdr)e.Row;
MyLine line =
PXSelect<MyLine, Where<MyLine.hdrID, Equal<Current<MyHdr.hdrID>>>>
.SelectSingleBound(this, new object[] { e.Row });
if (line == null)
throw new PXSetPropertyException(Messages.NoLines, PXErrorLevel.Warning);
line =
PXSelect<MyLine, Where<MyLine.hdrID, Equal<Current<MyHdr.hdrID>>, And<MyLine.inventoryID, NotEqual<Null>>>>
.SelectSingleBound(this, new object[] { e.Row });
if (line != null)
throw new PXSetPropertyException(Messages.NoInventoryID, PXErrorLevel.Warning);
}
#endregion
I have CommitChanges = True on the Inventory ID field, so it seems a special technique is required to validate the grid lines when validating the header hold field.
How do I look into the unsaved data on the grid (child lines of the header) to validate without making the user persist the records first?
