What i want to achive is for a field to update based on the vaule of another, but its held in another table.
I have a UD field in the OrderHead table, now i want this updated depending on what value is in the “CustIC.ICCode” field. This need to be connected to which customer is on the order
I did something very similar recently. I used 4 method directives, one on each of these methods, all post-processing:
SalesOrder.CreateOrderFromQuote
SalesOrder.ChangeCustomer
Quote.CreateOrderFromQuote
Quote.GetCustomerInfo
and that seemed to cover every scenario. I’m sure you could do it all in one Data Directive on OrderHed, but it would take a good amount of restrictions to make sure you get what you want at the right time and when it’s actually available. Either way, make sure to check for nulls.
You won’t be able to get the CustIC field using that option, as it isn’t one of the tables in the SalesOrderTableset. You can get the IC Code using a LINQ query if you put it in a custom code block like the one below. If you set a BPM string variable, you can persist the ICCode so you can later use it to update your sales order UD Field.
// For the Customer Level ICCode
var ICCode = Db.CustIC
.Where( x => x.CustNum == iCustNum && x.ShipToNum == "" )
.Select( s => x.ICCode )
.FirstOrDefault();
// Sometimes ShipTo locations may have a different ICCode
string ShipTo = ds.OrderHed
.Where( x => x.Updated() || x.Added() )
.Select( s => s.ShipToNum )
.FirstOrDefault();
var ICCode = Db.CustIC
.Where( x => x.CustNum == iCustNum && x.ShipToNum == ShipTo )
.Select( s => x.ICCode )
.FirstOrDefault();