Proforma Discount Calculation

Hello all,

I’m trying to calculate the discount value of a column in OrderHed the column name is: ProformaDisc_c which is set to decimal and for one of our orders in test database it’s set to 50.00%

I have been trying to some stuff in a BPM would this work?

var ProfromaDisc = (from orderHed in Db.OrderHed
                   
                   where orderHed.OrderNum == OrderNum
                   select orderHed.DocTotalCharges /100 * orderHed.ProformaDisc_c
                   ).ToList().Sum();

using (var txScope = IceContext.CreateDefaultTransactionScope())
{

foreach (var OrderHed in (from OrderHedRow in Db.OrderHed
where OrderHedRow.Company == Session.CompanyID 
&& OrderHedRow.OrderNum == OrderNum
select OrderHedRow))
{
TotalProformaDiscount = Convert.ToDecimal(ProformaDisc);
OrderHed.ProformaDiscTotal_c =  Convert.ToDecimal(ProformaDisc); 
}


 Db.Validate();
 txScope.Complete();
}   

When is this being triggered?
If it is on a Save (aka “Update” or “MasterUpdate”) of the Order, then you don’t need as much code.

Hi Jason,

Yes It’s triggered off update.

Thanks
Aaron.

You should just be able to use the Set Field widget then.
The only code is the math.