Order Entry Credit Hold

I added a check box (Line is on hold) on the line detail page. I check to see if the customer or order is on credit hold and if credit override is set or not.

This all works and checks the check box if it’s on credit hold and unchecks it if it’s not. My problem is it is not checking or unchecking the box unless you change something on the sales order and select save.

Currently I have it on the OrderDtl - In-Transaction. I’ve tried moving it to method directives Erp.BO.SalesOrder.Update reprocessing neither works. Any suggestions?

var c = ttOrderDtl.FirstOrDefault(x => x.RowMod == "U");

if (c != null)
{
    var y = Db.OrderHed.FirstOrDefault(x => x.Company == c.Company && x.OrderNum == c.OrderNum);
    
    // Added null check for y and y.PONum (though PONum check is usually optional unless business logic requires it)
    if (y != null)
    {
      
        var b = Db.Customer.FirstOrDefault(s => s.Company == y.Company && s.CustNum == y.CustNum);
        
        if (b != null) 
        {
        
             // If Customer is on Hold OR Order is on Hold
            if (b.CreditHold || y.OrderHeld)
            {
                // If there is an override, release the line hold, otherwise set it
                bool shouldHold = !y.CreditOverride;
                c.SetUDField<bool>("LineHold_c", shouldHold);
            }
        }
    }
}```

Try removing the rowmod check. The code is saying to only apply the logic to rows that have been changed. Also, be aware that if a row hasnt changed it wont appear in the dataset so if you have many rows and the state has changed since last update IE Credit hold has been triggered while putting lines on you could get a inconstant dataset.

Is there a reason you want to stamp the line and not inherit the status from the orderhed when the orderline is displayed in places?

The business wants the ability to put a specific line on credit hold due to the cost of the items. We make big HVAC units so the cost of one item may be substantial.

Right that makes sense, hook the GetNewOrderDtl on the sales object (thats about the right name) then populate the tickbox when the row is created. This should be a post method call.