Using method variables in a BPM

adminEpicor Coding

Requirement

I recently had to write a in transaction data directive on the OrderHed that stops the user from setting an order as 'Ready To Fuflfil' if a custom field against a part was flagged.

Approach

My first approach was to create a condition that queried the OrderDtl table based upon the OrderNum in the ttOrderHed table. If any records in the OrderDtl table referenced a flagged part that raise an exception.

This worked OK, but gave a rather generic answer to the user that a part existed somewhere in the order that was flagged. It did not highlight the part or parts within the order.

The solution I used was to use create a method variable in the directive and then reference this in an 'Execute Custom Code' caller.

The code caller loop through each order detail record appending an invalid parts to the method variable.

I then checked the method variable to see if it contained any text.

If it did, then return an exception message using the method variable as a value.

//clear the method variable
PartonFulfilHold = "";

//get the ordernum value
var ttOrderHed_xRow=(from ttOrderHed_Row in ttOrderHed  select ttOrderHed_Row).FirstOrDefault();

//get the row set for OrderDtl joined to Part
var partResultRows = from orderdtlRow in Db.OrderDtl
 where orderdtlRow.Company == Session.CompanyID &&
 orderdtlRow.OrderNum  == ttOrderHed_xRow.OrderNum
 join partRow in Db.Part
 on new { orderdtlRow.Company, orderdtlRow.PartNum }
 equals new { partRow.Company, partRow.PartNum }
 select new {orderdtlRow.PartNum, partRow.PackingHold_c};

//loop through each OrderDtl record
foreach(var partResult in partResultRows)
 {
    //if the condition id met append to the variable
    if (partResult.PackingHold_c)
    {
      PartonFulfilHold = PartonFulfilHold  + partResult.PartNum.ToString() + ",";
    }
 
 }

//remove leading comma
PartonFulfilHold = PartonFulfilHold.Remove(PartonFulfilHold.LastIndexOf(','));