Update JobHead.UserChar2 on MRP Job creation with value from Part.Condition

I would like to populate JobHead.UserChar2, when MRP creates a job, with the value from the Part.Condition field for the given part on the MRP job.

I have tried with an in-transaction data directive with the following code:

string msg = "#### JobHead.Update > In-Transaction Data Directive > MRP Job created ####\n\n";

foreach (var ttJobHeadRow in ttJobHead)
{
    msg += "JobNum: " + ttJobHeadRow.JobNum + "\n"; 
    msg += "Company: " + Session.CompanyID + "\n"; 
    msg += "PartNum: " + ttJobHeadRow.PartNum + "\n"; 
    var PartRow = (from row in Db.Part
                    where row.Company == Session.CompanyID && row.PartNum == ttJobHeadRow.PartNum
                    select new {row.Condition}).ToList().FirstOrDefault();
    if (PartRow != null)
    {
        msg += "Part Status: " + PartRow.Condition + "\n";
        // Add part status to userchar2
        ttJobHeadRow.UserChar2 = PartRow.Condition;
    }
}

Ice.Diagnostics.Log.WriteEntry(msg);

The output of the above code suggests that ttJobHeadRow.PartNum is null at the time the code is executed, so UserChar2 does not get updated.

Output:

#### JobHead.Update > In-Transaction Data Directive > MRP Job created ####

JobNum: MRP00000017072
Company: EPIC06
PartNum: 

So I guess a standard directive is required? How would I update the JobHead table in a standard directive in a custom code widget? I assume the ttJobHead table is unavailable by then, so would need to call an update service perhaps?

You could add a data tag on in the In-Trans data directive, then create a standard directive that starts with the condition that it contains that data tag. When ttJobHead has the data tag:

  1. remove the data tag so it doesn’t fire every time that JobHead updates
  2. get your Part.Condition.
  3. Invoke the JobEntry.GetByID (I think) BO method to get the Job Dataset.
  4. Set the UserChar2 in the Job Dataset.
  5. Invoke the JobEntry.Update BO Method.

Custom Code Conditional widget “Get Part.Conditon”:

var JobPart = ttJobHead.Where( x => x.Added() || x.Updated() )
                        .Select( s => s.PartNum )
                        .FirstOrDefault();


if ( string.IsNullOrEmpty(JobPart) ) return false;


PartCondition = Db.Part.Where( x => x.PartNum == JobPart )
                           .Select( s => s.Condition )
                           .FirstOrDefault();

return true;

P.S.
Is there more to this BPM than you’ve posted? I don’t see any condition that would restrict this to Jobs being created or created by MRP. Based on this, it will fire on every change to the jobhead table.

1 Like

Hi Kevin, thanks for the suggestion.

Yes there is a condition ahead of the code:
image

1 Like

Perfect. Just wanted to make sure. Welcome to the forum, btw!

1 Like

Welcome @tom_osborne !
One thing you might consider: Perhaps that part number gets added during an update and not an add? Just thinking out loud. Something to try.

2 Likes

Oh yeah, if that’s the case then the standard directive I suggested won’t work as-is. However, if you were to change the first conditional widget (labeled “Has DataTag”) to include a second condition to check for a PartNum (below), then it would leave the data tag until the part num is added.

This was it, thank you! Not sure why I hadn’t thought of that.

I changed my conditions as follows:

This now updates JobHead.UserChar2 within the in-transaction Data Directive with the same code as posted in my original post.

2 Likes