0
votes

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?

1
You can do dataview.Select() or check in the Inserted/Updated collections of Caches[typeof(DAC)].Inserted. - Hugues Beauséjour

1 Answers

1
votes

Look up the name of the data view: enter image description here

You then call the Select method of the data view to get the records.

For new graph inheriting from PXGraph:

foreach (SOLine line in Transactions.Select())
{
}

For graph extensions inheriting from PXGraphExtension you need to add the Base prefix:

foreach (SOLine line in Base.Transactions.Select())
{
}

For data views that contain multiple DACs, you can access them with PXResult.

> PXSelect<DAC1, InnerJoin<DAC2>, LeftJoin<DAC3>>

foreach (PXResult<DAC1, DAC2, DAC3> results in DataView.Select())
{
    DAC1 dac1 = (DAC1)results;
    DAC2 dac2 = (DAC2)results;
    DAC3 dac3 = (DAC3)results;
}

Finally, all data displayed on screen should be in one of the cache collections. This one also need to be prefixed by Base if used in the context of a graph extension:

foreach (SOLine line in Caches[typeof(SOLine)].Inserted)
{
}

foreach (SOLine line in Caches[typeof(SOLine)].Updated)
{
}