Data Directive to update UD Field

I have a data directive running when we approve a Part Revision. I would like to store information from the BOM in a specific instance to PartRev.Number02 so that I can use it elsewhere for reports, form customisations, etc without having to drag the PartMtl table in.

This is the code I have for my Data Directive (I assume I have to use Custom Code as I need the information from the PartMtl table):

// Link to PartMtl table to update PartRev.Number02 with QtyPer of 1kg Material

Ice.Diagnostics.Log.WriteEntry("zBPM:  PartRev.Update");
Erp.Tables.PartMtl PartMtl;
Ice.Diagnostics.Log.WriteEntry("zBPM:  PartRev.Update - PartMtl Table added");

foreach (var ttPartRev_iterator in (from ttPartRev_Row in ttPartRev
where string.Equals(ttPartRev_Row.RowMod, IceRow.ROWSTATE_UPDATED, StringComparison.OrdinalIgnoreCase)
&& ttPartRev_Row.Company == Session.CompanyID
select ttPartRev_Row))
{ var ttPartRev_Row = ttPartRev_iterator;
   PartMtl = (from PartMtl_Row in Db.PartMtl
       where PartMtl_Row.Company == ttPartRev_Row.Company
       && PartMtl_Row.PartNum == ttPartRev_Row.PartNum
       && PartMtl_Row.RevisionNum == ttPartRev_Row.RevisionNum
       && PartMtl_Row.MtlPartNum.StartsWith("1kg")
       select PartMtl_Row).FirstOrDefault();
Ice.Diagnostics.Log.WriteEntry("zBPM:  PartRev.Update - PartMtl.PartNum - Revision - MtlPartNum - QtyPer: " + PartMtl.PartNum + " - " + PartMtl.RevisionNum + " - " + PartMtl.MtlPartNum + " - " + PartMtl.QtyPer);
   if (PartMtl != null)
        Ice.Diagnostics.Log.WriteEntry("zBPM:  PartRev.Update - PartMtl.PartNum - Revision - ttPartRev.Revision: " + PartMtl.PartNum + " - " + PartMtl.RevisionNum + " - " + ttPartRev_Row.RevisionNum);
        Ice.Diagnostics.Log.WriteEntry("zBPM:  PartRev.Update - PartMtl.PartNum - Revision - ttPartRev.Revision + ttPartRev.Number02 BEFORE: " + PartMtl.PartNum + " - " + PartMtl.RevisionNum + " - " + ttPartRev_Row.RevisionNum + " - " + ttPartRev_Row.Number02);
           ttPartRev_Row.Number02 = PartMtl.QtyPer;
        Ice.Diagnostics.Log.WriteEntry("zBPM:  PartRev.Update - PartMtl.PartNum - Revision - ttPartRev.Revision + ttPartRev.Number02 AFTER: " + PartMtl.PartNum + " - " + PartMtl.RevisionNum + " - " + ttPartRev_Row.RevisionNum + " - " + ttPartRev_Row.Number02);

The lines below from the Server Log show that the code is running:

But when I run my BAQ to verify the field hasn’t updated:

Is it because I am updating a temp table \ ud field? I feel I must be missing something obvious but am running out of ideas of where to look.

I needed to update the PartRev table and not ttPartRev.

This code will set the parent rev’s number02 field to the qty needed of the first child partnum that starts with 1KG.

Why not just set the field directly to the parent rev? or parent part?

Is it a Standard Directive or a In-Tran Directive? I’ve found the STD’s are only good for triggering, as they happen after the table has been updated. Setting any of the fields of the changed record don’t do anything because they’ve already been written to the table.

And the thing with In-Trans, is that you can’t rely on what is in the table, because it hasn’t been updated yet.

Although we don’t currently have the issue, there is a possibility we could have 2 approved revisions for the same part with different weights (re-works, etc) so I was future proofing :slight_smile:

It is Standard as I needed the trigger after the part was definitely approved. Seems to be working now :slight_smile: