Updating Order Header UD field based on Order Detail/Line

, ,

Make a Standard DD on Update, or a Method Directive on Update.
In post, check for any dtl lines that meet your criteria.
Update field appropriately.

Method directive on Update-> post processing works I guess.

Need to keep this code through loops. Any examples? Sorry for having those questions. Not that good at coding.

So, for my case:

I created a field at Order-Hed level to store values under SO form. With help of BPM it worked. Took the easy way I believe.

Created a BPM at SalesOrder.Update->PreProcessing
Condition:

Added argument/variable to keep count of number of lines

Used Custom Code to display value in Custom Orderhed field.

// …
Erp.Tables.OrderHed OrderHed;

var OrderDtlRow = ttOrderDtl.FirstOrDefault();
int OrderNum = (int)OrderDtlRow.OrderNum;

OrderHed = (from OrderHed_row in Db.OrderHed
where OrderHed_row.Company == Session.CompanyID
&& OrderHed_row.OrderNum == OrderNum
select OrderHed_row).FirstOrDefault();

if (OrderHed != null)
{
// Get the previous count
decimal previousCount = OrderHed.TotalQuantities1_c;

// Add the current count
decimal newCount = previousCount + Count1;

OrderHed.TotalQuantities1_c = newCount;

}

This way whenever a new line is added, system will look for custom part and adds a value in the Custom field at Orderhed.
I reversed the condition and custom code if line is deleted. This way it subtracts the values.

Code:
image

I used this value at my email notifications. If value is not equal to 0 means there is a ZZZ part and send an email.

Thank you everyone for your valuable time and input. Much appreciated !! Grinning face with big eyes|20pxx20px

Glad you got a solution. If you can get the .Any statement working it does the same without any looping or math in the one line.

2 Likes