Custom BPM to add QuoteHed_UD field to Sales Order on Opp to Sales Order processing

You might want to add a few additonal lines of code:

  1. a line for the Transaction Scope
  2. add a “lockHint.UpdLock” for record locking
  3. DB.Validate
  4. txScop.Complete

I also moved the read for the order down into the inside of the scop as well as inside the checking for the null quote. No need to read the order if you are not going to modify it.

var quoteNum = Db.OrderDtl.Where(o => o.Company == Session.CompanyID && o.OrderNum == orderNum).Select(x => x.QuoteNum).FirstOrDefault();
if (quoteNum != null) {
    var quote = Db.QuoteHed.Where(q => q.Company == Session.CompanyID && q.QuoteNum == quoteNum).Select(x => new { x.DecorType_c, x.BldgType_c }).FirstOrDefault();
    if (quote != null) {
        //UD fields to copy to SO from Quote BldgType

        using(var txScope = IceContext.CreateDefaultTransactionScope()) {
            var order = Db.OrderHed.With(LockHint.UpdLock).Where(o => o.Company == Session.CompanyID && o.OrderNum == orderNum).FirstOrDefault();
            order.DecorType_c = quote.DecorType_c;
            order.BldgType_c = quote.BldgType_c;
            Db.Validate();
            txScope.Complete();
        }
    }
}