I am not sure if I am taking the best path forward, but here is what I am trying to do.
When an order is created with a specific ShipTo location for a specific Part, I want to capture the OrderDtl.PickListComment, and add some additional verbiage on that comment for each line that matches the part number.
Initially I started looking at using multiple Method Directive on SalesOrder.ChangeShipToCustID and SalesOrder.ChangeShipToID and SalesOrder.GetNewOrderDtl and SalesOrder.ChangePartNum and SalesOrder.ChangePartNumMaster; trying to cover all situations like the CSR adding the lines then changing the ShipTo, or selecting the ShipTo and then changing or adding lines. I could not get that to work like I wanted.
So I tried the SalesOrder.Update pre-processing with:
The first condition: (ds.OrderHed.ReadyToFulfill field has been changed from False to True) AND (The ds.OrderHed.ShipToCustNum field of the changed row is equal to the XCUSTNUMX expression) AND (The ds.OrderHed.ShipToNum field of the changed row is equal to the “XSHIPTONUMX” expression)
The second condition: Number of rows in the MyQuery is more or equal to 1:
My query looks like this:
Where the criteria on the ERP.OrderDtl is PartNum is equal to the specific part I am looking for.
So if there is at least one line where the part number matches, then this condition is true.
I used a show message widget so I could see what was getting captured. Data only existed on the ds.OrderHed table and NO data existed on the ds.OrderDtl table (because the update only happened on the header table and not the detail table).
Then I started looking to capture some variables, thinking I could use those to update the OrderDtl.PickListComment on Every line of the Sales Order that matches this specific part number.
I grabbed the “original” OrderDtl.PickListComment with the following expression:
(from x in Db.OrderDtl where x.OrderNum == dsOrderHedRow.OrderNum && x.PartNum == "XPartNumberX" select x.PickListComment).FirstOrDefault()
But I suspect the FirstOrDefault is only finding the first line that matches, when there could be multiple lines.
I grabbed the Line number of the specific part with the following expression:
(from x in Db.OrderDtl where x.OrderNum == dsOrderHedRow.OrderNum && x.PartNum == "XPartNumberX" select x.OrderLine).FirstOrDefault()
Once again, I suspect this is only capturing the first and not all occurrences.
How would I update my code to capture an array of all matches and then how would I write those changes back to the correct lines on the OrderDtl table?
Or am I doing this all wrong and should use a different approach?