Capture OrderHed, OrderDtl, and OrderRel ReqDate changes

Hey everyone, struggling to figure out how I do this. I need to capture any changes to the OrderHed, OrderDtl, and OrderRel RequestDate, and insert it to a UD table. The next step for this is displaying a Data Form, that will prompt the user for why they changed it.

It seems like its similar to @jgiese.wci 's BPM that he shows here. https://www.epiusers.help/t/bpmdata-form-error-e10/41226/3?u=chriskrajewski

I have tried some code from this thread also https://www.epiusers.help/t/orderhed-ud-field-bpm/116490?u=chriskrajewski

This allows me to get it sorta working, but with some NullReferenceExceptions when I touch anything related to the Unchanged row.

This is my ugly code if anyone wants to see it. Don’t be too harsh :rofl:

This sorta works, but with NullRef errors

// Select the OrderRel that has been Updated

    var newOrderRel = ds.OrderRel.FirstOrDefault(x => x.Updated());
    // If we have an updated row continue
    if(newOrderRel == null) return;
    
        var origOrderRel = ds.OrderRel.FirstOrDefault(x => x.Unchanged() && x.SysRowID == newOrderRel.SysRowID && x.ReqDate != newOrderRel.ReqDate).ReqDate;
        this.PublishInfoMessage($"New: {newOrderRel.ReqDate} RowMod: {newOrderRel.RowMod} OrigDate: {origOrderRel}", Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "", "");

        if (origOrderRel != null && origOrderRel != newOrderRel.ReqDate )
        {

            this.PublishInfoMessage($"{origOrderRel}", Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "", "");

        }

Once I have the Original, Changed, and eventually Data Form responses, this is what I am using to insert to UD02, and this works.

// Using the UD02Svc -> Add / Update Row 
    using(var svc = Ice.Assemblies.ServiceRenderer.GetService<UD02SvcContract>(this.Db)) 
    {
        var ds = new Ice.Tablesets.UpdExtUD02Tableset();
        {
        var row = new Ice.Tablesets.UD02Row() 
        {
            Company = callContextClient.CurrentCompany, // Current Company
            Key1 = "ShipDate.ReasonCode", // Name of Method Directive Responcible for Managing this Data
            Key2 = callContextBpmData.Number01.ToString(), // OrderNum
            Key3 = callContextBpmData.Number02.ToString(), // OrderLine
            Key4 = callContextBpmData.Number03.ToString(), // OrderRelNum
            Key5 = Guid.NewGuid().ToString(),
            Date01 = callContextBpmData.Date01, // Orginal ShipDate
            Date02 = ttOrderDtl_Row.RequestDate, // New ShipDate
            Character01 = callContextBpmData.Character01, // Reason Code Comment
            ShortChar01 = callContextClient.CurrentUserId, // UserID
            ShortChar02 = callContextClient.CurrentPlant.ToString(), // Current Plant
            Date03 = DateTime.Now

        };
            ds.UD02.Add(row); //'add to dataset'
        }
        
        string ErrorMessage = "";
        bool errorOccurred = false;
        BOUpdErrorTableset boUpdateErrors = svc.UpdateExt(ref ds, true, true, out errorOccurred);
        }

If anyone has any working example’s or BPM’s that they could share, or even help with pointing me in the right direction on this, I will be forever in your debt!

Thanks!
Chris

1 Like

Improvement to the Change Log Report would be useful… I’m not sure the impetuous for inserting the data into a UD table, but having access and eyes on the changes themselves from many tables provides a timeline

2 Likes

Just in case anyone else has this unique situation. Here’s how I was able to figure it out.

Here is the BPM Flow

First checking the OrderHed for a change, then OrderDtl, then finally OrderRel.

    foreach (var OrderHed_iterator in (from OrderHed_Row in ds.OrderHed
             where OrderHed_Row.RowMod == "U"
    select OrderHed_Row))

{
    var OrderHedRow = OrderHed_iterator;

    var orig = ( from drow in Db.OrderHed 
                where drow.Company == OrderHedRow.Company 
                   && drow.OrderNum == OrderHedRow.OrderNum
      select new { drow.RequestDate} ).FirstOrDefault();
      
      
         callContextBpmData.Number01 = OrderHed_iterator.OrderNum; //OrderHed Order Number
         callContextBpmData.Date01 = orig.RequestDate; //Orignal Ship Date
         callContextBpmData.Date02 = OrderHed_iterator.RequestDate; //New Ship Date

    
}

It gathers what changed (if anything) then asks the user for a reason, then logs that reason to UD02

using(var svc = Ice.Assemblies.ServiceRenderer.GetService<UD02SvcContract>(this.Db)) 
    {
        var ds = new Ice.Tablesets.UpdExtUD02Tableset();
        {
        var row = new Ice.Tablesets.UD02Row() 
        {
            Company = callContextClient.CurrentCompany, // Current Company
            Key1 = "ShipDate.ReasonCode", // Name of Method Directive Responcible for Managing this Data
            Key2 = callContextBpmData.Number01.ToString(), // OrderNum
            Key3 = callContextBpmData.Number02.ToString(), // OrderLine
            Key4 = callContextBpmData.Number03.ToString(), // OrderRelNum
            Key5 = Guid.NewGuid().ToString(),
            Date01 = callContextBpmData.Date01, // Orginal ShipDate
            Date02 = callContextBpmData.Date02, // New ShipDate
            Character01 = callContextBpmData.Character01, // Reason Code Comment
            ShortChar01 = callContextClient.CurrentUserId, // UserID
            ShortChar02 = callContextClient.CurrentPlant.ToString(), // Current Plant
            Date03 = DateTime.Now

        };
            ds.UD02.Add(row); //add to dataset
        }
        
        string ErrorMessage = "";
        bool errorOccurred = false;
        BOUpdErrorTableset boUpdateErrors = svc.UpdateExt(ref ds, true, true, out errorOccurred);
        }
        
        //Clear CallContextData
        callContextBpmData.Date01 = null;
        callContextBpmData.Date02 = null;
        callContextBpmData.Number01 = 0;
        callContextBpmData.Number02 = 0;
        callContextBpmData.Number03 = 0;

I have the actual BPM attached if anyone does want to use it!

ShipDate.RsnCode-Pre.bpm (103.0 KB)

3 Likes