Hello,
we have a little customization that to count each ship line’s qty according to the item’s temperature zone(which is also a customization field, but it does not matter here).
It would be almost perfect, however it is having a little issue.
If someone clear/delete all ship lines and save, the “totaldryunits” would not be set to 0.

I read the code lines, it looks like
foreach (SOShipLine line in Base.Transactions.Select())
this line would not be triggered, if all ship lines were cleared.

I am not good at coding , can anyone help me how to trigger the total reset?
Best answer by Naveen B
Hi
We can not include the above logic in the cache attached event, but instead of having this code “RowSelected” it's better to write a code in the RowUpdated event and it is the recommended approach.
I have modified the above code a little bit. Please find the code below and verify.
Hope this helps!!
protected void SOShipment_RowUpdated(PXCache cache, PXRowUpdatedEventArgs e, PXRowUpdated InvokeBaseHandler)
{
InvokeBaseHandler?.Invoke(cache, e);
var row = (SOShipment)e.Row;
if (row == null) return;
decimal totalUnits = 0M;
decimal totalDryUnits = 0M; //to calculate only dry items 20201009
foreach (SOShipLine line in Base.Transactions.Select())
{
InventoryItem item = PXSelect<InventoryItem, Where<InventoryItem.inventoryID, Equal<Required<InventoryItem.inventoryID>>,
And<InventoryItem.stkItem, Equal<boolTrue>>>>.Select(Base, line.InventoryID); //Only stock item count shipped units, non-stock did not count
if (item != null)
{
SOShipLineExt soShipLineExt = line.GetExtension<SOShipLineExt>();
var units = 0M;
if (soShipLineExt.UsrCWT == true) //For CWI, did not use shipped qty as shipped units, using split lines instead
{
units = Convert.ToDecimal(soShipLineExt.UsrTotalWgt);
}
else
{
units = Convert.ToDecimal(line.Qty);
}
totalUnits = totalUnits + Convert.ToDecimal(units);
if (item.GetExtension<InventoryItemExt>().UsrTempZone == 0)
{
totalDryUnits = totalDryUnits + Convert.ToDecimal(units);
}
}
}
cache.SetValueExt<SOShipmentExt.usrTotalUnits>(row, Convert.ToDecimal(totalUnits));
cache.SetValueExt<SOShipmentExt.usrTotalDryUnits>(row, Convert.ToDecimal(totalDryUnits));
}