Add Order Misc Charge BPM

I am getting stuck. GetNewOHOrderMsc does not seem to be populating a new row in the OrderMsc table for me to use. That NewMiscCharge variable comes back null every time. Is there something I am missing here?

var OrderInfo = (from o in ttOrderHed
                 where o.RowMod == "U" && o.Company == callContextClient.CurrentCompany
                 select o).FirstOrDefault();
if (OrderInfo != null)
{    
  var OrderNum = OrderInfo.OrderNum;
  var CustNum = OrderInfo.CustNum;
  decimal OrderAmt = OrderInfo.OrderAmt;
  decimal Pct = .03M;

  info += "OrderNum: " + OrderNum + "\nCustNum: " + CustNum + "\nOrderAmt: " + OrderAmt + "\nPct: " + Pct + "\n";
  
  Erp.Contracts.SalesOrderSvcContract boSalesOrder = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.SalesOrderSvcContract>(Db);
  Erp.Tablesets.SalesOrderTableset dsSalesOrder = new Erp.Tablesets.SalesOrderTableset(); 
  
  dsSalesOrder = boSalesOrder.GetByID(OrderNum);

  boSalesOrder.GetNewOHOrderMsc(ref dsSalesOrder, OrderNum, 0);
 
  var NewMiscCharge = (from m in dsSalesOrder.OrderMsc
                       where m.RowMod == "A" && m.Company == callContextClient.CurrentCompany
                       select m).FirstOrDefault();

//  if (NewMiscCharge != null)
//  {    
//    bool lCheckForOrderChangedMsg = true;
//    bool lcheckForResponse = true;
//    string cTableName = "OHOrderMsc";
//    int iCustNum = CustNum;
//    int iOrderNum = OrderNum;
//    bool lweLicensed = false;
//    bool lContinue = false;
//    string cResponseMsg = "";
//    string cCreditShipAction = "";
//    string cDisplayMsg = "";
//    string cCompliantMsg = "";
//    string cResponseMsgOrdRel = "";
//    string cAgingMessage = "";

    NewMiscCharge.MiscCode = "CCFE";
    boSalesOrder.ChangeMiscCode(ref dsSalesOrder, "OHOrderMsc");    

    NewMiscCharge.MiscAmt = OrderAmt * Pct;
    boSalesOrder.ChangeMiscAmount(ref dsSalesOrder, "OHOrderMsc");
    
    NewMiscCharge.FreqCode = "F";  
    NewMiscCharge.SeqNum = 1;    

    boSalesOrder.Update(ref dsSalesOrder);
//  }

}

I know that I am getting my OrderInfo to populate as well as the dsSalesOrder. I can write a different query to the OrderDtl table within the dataset and see the information from my order. But it doesn’t seem to be setting up the new row in OrderMsc.

Only thing I can think of is that you also need to set a few more variables, before Update.

 NewMiscCharge.CurrencySwitch = false;
 NewMiscCharge.DocDspMiscAmt = miscAmount;
 NewMiscCharge.DocMiscAmt = miscAmount;
 NewMiscCharge.Type = "A";

I added those… but my problem seems to be here:

  boSalesOrder.GetNewOHOrderMsc(ref dsSalesOrder, OrderNum, 0);
 
  var NewMiscCharge = (from m in dsSalesOrder.OrderMsc
                       where m.RowMod == "A" && m.Company == callContextClient.CurrentCompany
                       select m).FirstOrDefault();

I am not getting this row to be retrieved from the query. NewMiscCharge comes back null. Is there a better way to “get a new misc charge”?

Bah. I think I found it. I needed to be using OHOrderMsc in the from statement. Should’ve been:

  var NewMiscCharge = (from m in dsSalesOrder.OHOrderMsc
                       where m.RowMod == "A" && m.Company == callContextClient.CurrentCompany
                       select m).FirstOrDefault();

Any idea why I would keep getting the “Row has been modified by another user and couldn’t be updated” BLE? It seems to happen anytime I set the DocDspMiscAmount field. If I don’t set that field, the amount does not show up on the misc charge. It just shows 0. Even after I get the BLE, it still adds the charge but it doesn’t save the change I made to the header to initiate the BPM to execute.

I believe it’s related to the fact that when I add the misc charge successfully, it forces an update to the OrderHed table as it changes the OrderAmt. So the OrderHed row gets locked at that time.

Ok. So then my question is: is there a better way to do what I am trying to do other than a pre-processing on the MasterUpdate?

Dan,
Did you ever get this working or find a better way to do this? I’m running into the same issue with the “row modified by another user” error.

Yes, for Orders I moved it to Post-Processing. I used an in-trans data directive for the Quotes (not sure if you’re there yet or already past it but don’t forget about quotes! The Order does not update like you’d want it to when you convert a quote to an order - so you need to have it right on the quote before you convert it to an order).

We added the miscellaneous charge specifically for credit card orders > $1000. To make sure it was a credit card order, we checked the Payment Terms.

If I remember correctly, I had to write a LINQ statement to retrieve the order amount and terms code from the database because it was not populated in the temp-table dataset that you get at post-processing. Pics below for reference.

Get OrderAmt

(from o in Db.OrderHed
 where o.Company == callContextClient.CurrentCompany
 && o.OrderNum == iOrderNum
 select o.OrderAmt).FirstOrDefault()

Get TermsCode

(from oh in Db.OrderHed
 where oh.Company == callContextClient.CurrentCompany
 && oh.OrderNum == iOrderNum
 select oh.TermsCode).FirstOrDefault()

Add Misc Charge


  var OrderNum = iOrderNum;
  var CustNum = iCustNum;
  decimal OrderAmt = OrderAmt;
  
  bool ExistingCharge = false;
  var MiscCharges = (from om in Db.OrderMsc
                      where om.OrderNum == OrderNum
                      && om.Company == callContextClient.CurrentCompany
                      select om);
  
  if (MiscCharges.Any())
  {
    foreach (var EachCharge in MiscCharges)
    {
      if (EachCharge.MiscCode == "CCFE")
      {
        ExistingCharge = true;
        break;
      }
  
    }    
  }
  
  
  if (OrderAmt > 1000 && !ExistingCharge)
  {
    decimal Pct = 3;
    decimal Amt = OrderAmt * Pct / 100;
    
    Erp.Contracts.SalesOrderSvcContract boSalesOrder = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.SalesOrderSvcContract>(Db);
    Erp.Tablesets.SalesOrderTableset dsSalesOrder = new Erp.Tablesets.SalesOrderTableset(); 
    
    dsSalesOrder = boSalesOrder.GetByID(OrderNum);
  
    boSalesOrder.GetNewOHOrderMsc(ref dsSalesOrder, OrderNum, 0);
   
    var NewMiscCharge = (from m in dsSalesOrder.OHOrderMsc
                         where m.RowMod == "A" && m.Company == callContextClient.CurrentCompany
                         select m).FirstOrDefault();
  
    if (NewMiscCharge != null)
    {    
      bool lCheckForOrderChangedMsg = true;
      bool lcheckForResponse = true;
      string cTableName = "OHOrderMsc";
      int iCustNum = CustNum;
      int iOrderNum = OrderNum;
      bool lweLicensed = false;
      bool lContinue = false;
      string cResponseMsg = "";
      string cCreditShipAction = "";
      string cDisplayMsg = "";
      string cCompliantMsg = "";
      string cResponseMsgOrdRel = "";
      string cAgingMessage = "";   
      
      NewMiscCharge.MiscCode = "CCFE";
      boSalesOrder.ChangeMiscCode(ref dsSalesOrder, "OHOrderMsc");    
  
      NewMiscCharge.CurrencySwitch = false;
      NewMiscCharge.Type = "P";
      NewMiscCharge.Percentage = Pct;
      boSalesOrder.ChangeMiscPercent(ref dsSalesOrder, "OHOrderMsc");
      
      NewMiscCharge.MiscAmt = Amt;
      NewMiscCharge.DocMiscAmt = Amt;
      NewMiscCharge.DocDspMiscAmt = Amt;
      boSalesOrder.ChangeMiscAmount(ref dsSalesOrder, "OHOrderMsc");
      
      NewMiscCharge.FreqCode = "F";
  
      boSalesOrder.MasterUpdate(lCheckForOrderChangedMsg,
                                lcheckForResponse,
                                cTableName,
                                iCustNum,
                                iOrderNum,
                                lweLicensed,
                                out lContinue,
                                out cResponseMsg,
                                out cCreditShipAction,
                                out cDisplayMsg,
                                out cCompliantMsg,
                                out cResponseMsgOrdRel,
                                out cAgingMessage,
                                ref dsSalesOrder);
                                
      }
                                
    }

Any questions, don’t hesitate to ask.

1 Like

Thanks Dan. I was able to get it working! Ideally I want to duplicate this on orders that come in through EDI import so that will be the ultimate win.