BPM Refresh From- Sales Order Weight

Hi all,
I keep having an error saying “There are no records in the table ds.OrderHed Record not found.”


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.

You should add a condition to only run when the row doesn’t have a row mod of “D” for deleted.

Nice. It worked! You are indeed an Epicor Ninja @Banderson:slight_smile:

1 Like

Hi @Banderson , it looks like I put the condition on the wrong spot. Is it supposed to be added in the pre-processing?

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.
image.
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();
}

Here is my BPM design
image

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?)

image

That is right.
Pre-Processing


Post Processing

Big Thank you!! @Banderson

you could further enhance your C# code

  1. 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.
  2. 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();
}
1 Like

Hi @timshuwy , I tried this but it gives an error.
image

Sorry… it should have been:

if (OrderHed != null){
1 Like

Thank you @timshuwy

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?

Yes, this can be done through BPM condition…

Can you elaborate?



image