App Studio - Copy Change from OrderHed to all OrderRel

We added a UD column to the OrderHed and OrderRel tables called IsBackOrdered_c (bool). Whenever the column in OrderHed changes (either on save or right away), we want a popup displayed asking the user if they also want to update the Back Ordered status to all the releases.

What is the best approach for updating the releases?
Method Directive on MasterUpdate, App Studio, or combination of App Studio and Function?

I tried configuring it in App Studio but apparently wasn’t setting something up correctly because I wasn’t able to retrieve all the releases and update them.

I have it working in a Method Directive on MasterUpdate. The Pre-Processing checks if this column changed, if so, I then call a BPM Data Form to ask if they want all the releases updated. If yes, then Enable Post Directive and execute this c# code:

using (var txScope = IceContext.CreateDefaultTransactionScope())
{
    // Get the OrderHed record from the dataset
    var orderHed = (from hd in ds.OrderHed
                    select hd).FirstOrDefault();
    
    if (orderHed != null)
    {
        bool isBackOrdered = false;
        
        // Get the IsBackOrdered_c value from OrderHed
        var udFieldValue = orderHed["IsBackOrdered_c"];
        if (udFieldValue != null)
        {
            isBackOrdered = Convert.ToBoolean(udFieldValue);
        }
        
        // Query ALL OrderRel records from the database for this order
        var allOrderRels = (from rel in Db.OrderRel
                           where rel.Company == orderHed.Company
                           && rel.OrderNum == orderHed.OrderNum
                           && rel.OpenOrder == true
                           && rel.VoidRelease != true
                           && rel.IsBackOrdered_c != isBackOrdered
                           select rel);
        
        // Update each release
        foreach (var rel in allOrderRels)
        {
            rel["IsBackOrdered_c"] = isBackOrdered;
            Db.Validate();
        }
    }
    
    txScope.Complete();
}

Then run the Invoke BO Method on GetByID.

Is this a good approach?
Or would it be better to Invoke a Function to make the changes to all the releases instead of doing it inside the Execute c#.
Or from App Studio?

2 Likes

Just my initial thoughts… I’m not a code-guy. That being said, trying to do this in app-studio sounds like a pain. I think you’re right to look at a BPM.

Is this the only LINE on the order? Would it make more sense for the backorder to be on the line level? One part/line item could be backordered where another line of the same order is not. (unless “ship order complete” is always true in your organization)

Should you also filter out previous closed lines/releases? rel.OpenRelease == true

If a couple lines/releases already shipped then a backorder wouldn’t effect them. Not sure if closed lines/releases are inherently protected or not from such a method.

1 Like

There can be multiple lines.
We wanted to have it on the releases, since they would be able to send partial on the first shipment and create a new release for the back ordered amount. Adding it to the header gives us the option to cascade it to all the releases instead of opening every line/release. This checkbox is mainly for our scheduling team. If an order/release is flagged as back ordered, they will give it higher priority.

Yes, I think I have that in the OrderRel lookup within the code.
I also have a condition block in the Pre-Processing BPM that checks if the Back Ordered on the header changed from any to another.

1 Like