I have a Generic Inquiry screen showing batches to post. When I select a batch it brings up my form. If I make any changes to the form and click Cancel button, I get a warning that my changes will be lost. If I click to continue, the changes are undone. That works perfectly.
However, if I click Discard Changes and Close, I get a prompt that I will lose my changes. I click ok to continue and it takes me back to the Generic Inquiry screen. When I select that batch again, the form still reflects any changes I made to the Grid. The Description field is in the form section and it DOES NOT get saved when I reselect the batch to edit.
At this point, if I refresh the browser, it redisplays everything as unchanged (good).
This is what it looks like before I change anything:

If I untick the Errors to clear them, I am updating the details records to clear the errors on the line
protected void _(Events.FieldUpdated<ICSPending, ICSPending.hasErrors> e)
{
ICSPending row = e.Row;
if (row.HasErrors == false)
{
e.Cache.SetValue<ICSPending.hasAccountError>(row, false);
e.Cache.SetValue<ICSPending.hasSubaccountError>(row, false);
e.Cache.SetValue<ICSPending.hasBranchError>(row, false);
}
}
When all rows are clear of errors, the “Batch Has Errors” is set to false and the checkbox is hidden. I do this in the RowSelected of the header record
protected void _(Events.RowSelected<ICSPendingHDR> e)
{
ICSPendingHDR row = e.Row;
if (row == null) return;
//check if any rows have errors
bool rowhaserror = false;
foreach (ICSPending iCSPending in Details.Select()) {
if (iCSPending.HasErrors == true) rowhaserror = true;
}
Post.SetEnabled(row.Status == ICSEntryStatusConstants.Unposted &&
Headers.Cache.GetStatus(row) != PXEntryStatus.Inserted &&
!rowhaserror);
e.Cache.SetValue<ICSPendingHDR.hasErrors>(row, rowhaserror);
PXUIFieldAttribute.SetVisible<ICSPendingHDR.hasErrors>(e.Cache, row, rowhaserror);
}
This is what it looks like if after I make changes:

After clicking Discard and reselecting the batch, this is what it looks like:

Note that the Description field did not persist but the changes I made to the Grid did.
Refreshing the browser will reset the form so it is back to its unchanged state.
How can I clear out the cache changes I made in the Grid when I click Discard Changes and Close?
Thanks,
Joe