First off, a couple of warnings about some things that can trip up your initial logic.
There is a NeedBy date on each of the tables: OrderHed, OrderDtl, and OrderRel.
The values in OrderRel will be blank if not explicitly set. This means they will use the need by of their related OrderDtl.
Similarly, the values in OrderDtl will be blank if not explicitly set. This means they will use the need by of their related OrderHed.
So if someone updates the NeedBy on a Order Line or Release, it would not reflect as a change in the OrderHed.NeedBy.
Secondly, if your basing the BU on the product group, there can be different ProdGrp’s specified on an order, as each line can have a different PG. In this case would you want the email to go out to all BU’s for each different PG in the order?
Assuming you’re aware of all the above, and just want to get the PG from the first line on the Order, you could use a Variable and a Set Variable widget to fetch that PG.
- Create variable:
PG
- Set Variable/Argument widget to set PG with the following code
Db.OrderDtl
.Where( r =>r.Company == callContextClient.CurrentCompany && r.OrderNum == ttOrderHedRow.OrderNum)
.Select( r =>r.ProdCode).DefaultIfEmpty("").FirstOrDefault()
Now you have the ProdGrp in variable PG.
edit
The reference to ttOrderHedRow.OrderNum
in the above should actually be dsOrderHedRow.OrderNum