Create Order Misc Charge from Custom

Hi all!

I’m trying to create a new Order Misc Charge within the Customization’s code.

I used an old thing I did (with some help) for the Quote (same thing).

string msg = string.Empty;
var ttOrderHed_Row = (from row in ttOrderHed select row).FirstOrDefault();
//where row.Added() || row.Updated() 
if (ttOrderHed_Row != null)
{
var orderNum = ttOrderHed_Row.OrderNum;
msg += "Added MiscCharge (ExtraVerniciatura) for OrderNum: " + orderNum.ToString();
using (var orderSvc = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.OrderSvcContract>(this.Db))
{
  // This code adds / updates a header Misc Freight Charge        
  Erp.Tables.QuoteMsc OrderMsc;
  int orderLine = 0;
  int qtyNum = 0;
  string sMiscCode = "E001";
  string sMiscDesc = "Extraverniciatura";
  string sMiscFreq = "E";
  decimal dTotAmt = price;
  var soTs = new OrderTableset();
    // Check if the Freight Record exists already
  var OrderMsc_Row =  (from row in Db.OrderMsc where row.OrderNum == orderNum && row.MiscCode == sMiscCode && (string.Compare(row.Company, Session.CompanyID, true) == 0 ) select row).FirstOrDefault(); 
  if ((OrderMsc_Row == null))
  {
      orderSvc.GetNewOrderHedMsc(ref soTs, orderNum, orderLine, qtyNum); 
      var orderMscNew = soTs.OrderHedMsc.FirstOrDefault();  
      orderMscNew.MiscCode = sMiscCode;
      orderMscNew.Description = sMiscDesc;
      orderMscNew.FreqCode = sMiscFreq;   
      orderSvc.GetMiscChrgDefaults(ref soTs, "OrderHedMsc"); 
      orderMscNew = soTs.OrderHedMsc.FirstOrDefault();  
      orderMscNew.MiscAmt = dTotAmt;  
      orderMscNew.DocMiscAmt  = dTotAmt; 
      msg += System.Environment.NewLine + "Price: " + price;
  }
  orderSvc.Update(ref soTs);
  this.dsHolder.Attach(soTs);
}
}
this.PublishInfoMessage(msg,Ice.Common.BusinessObjectMessageType.Information,         Ice.Bpm.InfoMessageDisplayMode.Individual,"","");

This Code was working whitin the Quote (with the correct parameters) but for the Order it doesn’t work.

Can someone help me please?
Thanks!

Did you add the assembly reference?

No, I can’t tell which to add

Try referencing the assembly Erp.Contracts.BO.SalesOrder and then reference that service

using (var orderSvc = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.SalesOrderSvcContract>(this.Db))
1 Like

Thanks for the reply!
I tried but this is what I got:

It appears you left the old code in. You need to remove the old using statement since it is referencing a service that does not exist

Thanks

Tanner Post

Unfortunately nothing changes

I suspect it’s some name of the method due to not existing in the Order table while existing in the Quote one.

1 Like

The SalesOrderSvcContract uses SalesOrderTableset rather than OrderTableset. The methods you use GetNewOrderHedMsc and GetMiscChargeDefaults don’t look like they exist for the SalesOrderSvcContract. There’s a GetNewOrderMsc method that may do what you’re after.

1 Like

I managed to do this in with no code in the BPM but still I wanted to know how to do it like this :frowning:

1 Like

What kind of BPM is it?

It was a custom code from a SalesOrder.Update (POST)

You are about 90% there. Just needed to clean up your references to the correct services, tablesets, and methods. I believe you can find the names of these objects in the customization using the content assist feature (control + spacebar after entering namespace) in the customization editor screen. Unfortunately, the editor has a number of flaws and you pretty much have to work top down because the content assist feature fails as soon as it encounters invalid syntax. Once you get heavy duty into this, if you have VisualStudio, it is not very difficult to set up a project and load the BPM code in for better syntax checking. I believe there are threads on the forum that describe how to do this.

I see you have this working now using BPM widgets based on your response. You can also review the generated code which is under the server’s website folder in the BPM/Sources/BO/[BO Method]/ subfolders.

Hope this helps,
Tanner

Yes it definetly helps, thank you a lot.

Yeah I used VisualStudio before (with Epicor too), I will look through it.

And I didn’t know this, thanks again!

1 Like

Hi Leo,

I have come across your post as I am trying to do the same thing but in a BPM and seem to be struggling.

This is a Post Processing, condition where docamt is not more than 150, invoking getnewohmisc then invoking changemisccode then setting the fields finishing off with invoking masterupdate.

I am receiving an error that says
“There are no records in the table ttOrderDtl
OHOrderMsc record not available.
There are no records in the table ttOrderDtl”

Any help would be much appreciated.

Regards
Kirsty