Update custom field on order rel on all lines

Good morning all.

I need to update all of the order releases which has a custom field in it of LoadNum_c

I want to be able to place a data in a field on OrderHed_UD called LoadNum_c and when a user enters data into that field it will prompt stating that it will update all of the releases with the following information.

I’m not sure how to start with this one? It’s similar to the ShipVia.

Kind regards,
Aaron.

Create a data directive on OrderHed table and when the LoaNum_c has changed, add a custom code widget to update all Order rel.

You would need to read from the table and make the change for each and then save. something like

foreach(var Ord in (from r in ttJOrderHed where ( r.RowMod == "U") select r))
{
  relrows = Db.OrderRel.Where(x => ((x.Company == Ord.Company) && (x.OrderNum == Ord.OrderNum) ));
foreach(var row in relrows)
{
row["LoadNum_c"] = Ord.LoadNum_c;
}
Db.Validate;
}

or something like that ....  sorry i am not at the office....

Pierre
1 Like

@Hogardy is how I would do it as well… except you also need to surround the code with a SCOPE to make sure that everything is done right. I did a could of other little tiny cleanups on this:

using(var txScope = IceContext.CreateDefaultTransactionScope()) {
    foreach (var Ord in ttJOrderHed.Where(r => r.RowMod == "U")) {
        relrows = Db.OrderRel.Where(x => x.Company == Ord.Company && x.OrderNum == Ord.OrderNum);
        foreach (var row in relrows) {
            row["LoadNum_c"] = Ord.LoadNum_c;
        }
    }
    Db.Validate;
    txScope.Complete();
}

Hi Tim,

I got it working with this code with help from @hkeric.wci

Ice.Diagnostics.Log.WriteEntry($"PRE MasterUpdate for Order {iOrderNum}");

using (var txScope = IceContext.CreateDefaultTransactionScope())
{
  foreach(var Ord in (from r in ttOrderHed where r.Updated() select r))
  {
    var relRows = Db.OrderRel.Where(x => x.Company == Ord.Company && x.OrderNum == Ord.OrderNum).Select(x => x).ToList();
    
    foreach(var row in relRows)
    {
      Ice.Diagnostics.Log.WriteEntry($"Updating LoadNum_c for {Ord.OrderNum}");
      row["LoadNum_c"] = Ord["LoadNum_c"];
    }
    
    Db.Validate();
    txScope.Complete();
  }
}
1 Like