This BPM works fine when adding lines into the Sales Order but error shows up whenever user tries to delete a line from an order.
This BPM is used to calculate Sales Order weight.
Can someone help me on this please.
Yeah, what you will probably have to do is put the condition in pre-processing, and then use the “enable post processing directive” widget, so then you can trigger the post processing depending on if that was set or not.
Hi @Banderson, it seems like when I add the condition the BPM won’t fire. If I get rid of the condition, the BPM works but when user tries to do changes on the quote like removing attachments/deleting lines it gives an error saying "There are no records in the table ds.QuoteHed.
Record not found. .
Here is the code added on the BPM.
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
).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))
{
TotalWeight = Convert.ToDecimal(CalcWeight);
OrderHed.GrossWeight_c = Convert.ToDecimal(CalcWeight);
}
Db.Validate();
txScope.Complete();
}
Your code it fine, it’s your condition that isn’t working.
Use message boxes to figure out why your condition isn’t working. Drop in a message box, then in the message, right click and you can put the row information. Then you can see what rows are being returned and what the row mods are. (I’m assuming you did the pre-processing to decide whether to fire, then set the condition in the post processing to fire or not… right?)
you don’t need to do a “foreach” which is not efficient… you should just read the record with a “FirstOrDefault()” statement at the end. THere is only one record with that order number. Then you do an “IF” to make sure that it found something.
you should do a lock update on the select line.
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
).ToList().Sum();
using (var txScope = IceContext.CreateDefaultTransactionScope()){
var OrderHed = Db.OrderHed.With(LockHint.UpdLock).Where(x=>
x.Company == Session.CompanyID &&
x.OrderNum == OrderNum).FirstOrDefault();
if (!OrderHed == null){
TotalWeight = Convert.ToDecimal(CalcWeight);
OrderHed.GrossWeight_c = Convert.ToDecimal(CalcWeight);
}
Db.Validate();
txScope.Complete();
}
Resurrecting this old thread - we have the same requirement, and also the same problem. What I am not understanding about this discussion is, I do want the order weight to be recalculated when a sales order line is deleted - because that would change the weight of the order. Is it possible to do this somehow?