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:
remove the data tag so it doesn’t fire every time that JobHead updates
get your Part.Condition.
Invoke the JobEntry.GetByID (I think) BO method to get the Job Dataset.
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.
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.
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.