Customization or BPM to set PayFlag upon creation of Sales Order

@jscheffler I would put this post processing on SalesOrder.ChangeCustomer for normal processing to future proof the sales order entry process.

EDI does as you have seen bypass all of the salesorder processing, so you will need the same ish routine on DemandImportEntry.ImportProcessingDemand. This is the header section of my routine which is based on the thread below.

/* transfer from demand to order */



var DemandHeadRow =
  (from row in Db.DemandHead.With(LockHint.NoLock)
  where
    row.SysRowID == DemandHeadRowid
    && row.EDIOrder == true
    
  select row
  ).FirstOrDefault();

if (DemandHeadRow != null)
{
  
        /* Copy cust profile to sales order */

      var orderHedRow = Db.OrderHed.Where(oh => oh.Company == DemandHeadRow.Company && oh.OrderNum == DemandHeadRow.OrderNum ).FirstOrDefault();
      {
          using (System.Transactions.TransactionScope txScope = IceDataContext.CreateDefaultTransactionScope())//start the transaction
          {
               var Customer = Db.Customer.Where(Customer_Row => orderHedRow.CustNum == Customer_Row.CustNum && orderHedRow.Company == Customer_Row.Company).FirstOrDefault();
              {
                              
                  var shiptoRow = Db.ShipToMFBill.Where(st => st.Company == Session.CompanyID && st.CustNum == Customer.CustNum && st.ShipToNum == orderHedRow.ShipToNum).Select(st => new { st.PayBTFlag, st.PayAccount}).FirstOrDefault();
                  if (shiptoRow != null)
                  {
                    orderHedRow.PayFlag = shiptoRow.PayBTFlag;
                    orderHedRow.PayAccount = shiptoRow.PayAccount;
                    Ice.Diagnostics.Log.WriteEntry($" custID {Customer.CustID} PayAccount  {orderHedRow.PayAccount}");
                  }
              
              }
              txScope.Complete();//commit the transaction
          }
      }
    
}

2 Likes