Calculating Gross Weight of a Sales Order


it’s been a while since I put a post down, but this seemed such an obvious requirement, without a clear summary of how to code it.

This BPM calculates the gross weight of an order based upon the gross weight of the part on an order line multiplied by the quantity. It then popukates a custom field on the OrderHed_UD table called GrossWeight_c.

Finally, it refreshes the ‘Order Entry’ screen to display the new weight.


  • Create a ‘PostProcessing’ BPM on the SalesOrder.Update method
  • Calculate the gross weight of a line by multiplying the gross weight of the part by the line quantity
  • Update the GrossWeight_c field
  • Refresh the dataset using the GetByID method to refresh the form


  • Create an new post-processing method directive on the ‘SalesOrder.Update’ method – I called it ‘CalculateWeight’
  • Create two new variables
    • TotalWeight (decimal)
    • OrderNum (int0
  • Populate the OrderNum variable with the order number
  • Create a custom code widget – rename it ‘CalculateTotalWeight’
  • Add the following custom code to the widget
// Please keep in as a acknowledgement
// Written By Andrew Clements
// For Cobra Consulting Limited (
// Date: 23/03/2019
// v 1.0
// Desciption: Calculates total weight of an order 

var CalcWeight = (from orderDtl in Db.OrderDtl
                   join part in Db.Part on  orderDtl.PartNum equals part.PartNum
                   where orderDtl.OrderNum == OrderNum
                   select orderDtl.OrderQty * part.GrossWeight

using (var txScope = IceContext.CreateDefaultTransactionScope())

foreach (var OrderHed in (from OrderHedRow in Db.OrderHed
where OrderHedRow.Company == Session.CompanyID 
&& OrderHedRow.OrderNum == OrderNum
select OrderHedRow))
TotalWeight = Convert.ToDecimal(CalcWeight);
OrderHed.GrossWeight_c =  Convert.ToDecimal(CalcWeight); 

  • Refresh the dataset by calling the GetByID method, passing the OrderNum variable to refresh the ‘Order Entry’ form

Really simple BPM but has a multitude of uses where you need to update the header with order line summary info.

Finally for those in a hurry – here is the BPM

Download “CalculateWeightBPM” calculateweight.bpm – Downloaded 204 times – 30 KB