I have a custom field in the header of the Process Shipments screen header called Total Selected Price. There is also a custom field in the grid called Extended Price.
When a user selects a record in the grid, I want to update the total in the header.
I added CommitChanges = True to the Selected checkbox in the grid.
In my code, I added the following event handler to update the total when a checkbox is changed
protected void _(Events.FieldUpdated<SOShipment, SOShipment.selected> e)
{
SOShipmentFilter filter = Base.Filter.Current;
var row = (SOShipment)e.Row;
GTISOShipmentExt extLine = PXCache<SOShipment>.GetExtension<GTISOShipmentExt>(row);
if (extLine == null) return;
SOShipmentFilterExt extHeader = PXCache<SOShipmentFilter>.GetExtension<SOShipmentFilterExt>(filter);
if (extHeader == null) return;
if (row.Selected == true)
{
extHeader.UsrTotalSelectedPrice += extLine.UsrExtendedPrice;
}
else
{
extHeader.UsrTotalSelectedPrice -= extLine.UsrExtendedPrice;
}
}
Problem 1:
When the checkbox is changed, it is not firing this code. If I check the box and click the refresh on the screen (not refresh the entire page, the refresh button in the toolbar), this code is fired. But that logic will not increment/decrement the total as the checkboxes are selected/unselected.
Problem 2:
Then after it fires on a screen refresh, I can see that the total is being updated on the custom header field, but it is not actually updating the field on the screen. Perhaps even though I am setting a value in the custom header (filter section) field, it is being reset back to zero?
I tried using a PXFormula in the DAC extension to sum the values in the grid where the checkbox is selected, but you cannot put a condition in the PXFormula. I don’t know if that would do anything anyway since the cache only seems to update on a refresh of the screen.
I have a workaround using the RowSelected handler on the filter. Then I put a “dummy” action button on the screen to REFRESH SELECTED TOTALS which refreshes the screen to show the total.
I think if I could get the FieldUpdated to fire when the checkbox is updated, it would be a much cleaner solution.
FYI, I also tried setting the cache on the grid to allow updates. That didn’t make any difference in allowing the checkbox to fire.
Any ideas?