How to insert correctly new Sales order into Acumatica with external graph

Hello everybody,

today I want to write a short notice on how to create new sales order in Acumatica properly.

So, first of all take not that SOOrder type has two keys. One key is or order type, and second key is for OrderNbr.

It means that you can't do code like this:

var newSOrder = sOEntry.Document.Insert();
sOEntry.Document.SetValueExt<SOOrder.orderType>(sOEntry.Document.Current, sorder.AcumaticaOrderType);

or actually you can, but later you'll face some issues with duplicated sales orders ( as I recently faced ).

But what you should do if you wish create new Sales order is the following code snippet:

var newSOrder = new SOOrder();
newSOrder.OrderType = sorder.AcumaticaOrderType;
newSOrder = sOEntry.Document.Insert(newSOrder);

In this case you initialize first key value, which is OrderType, and then do insertion of sales order. 

If you do code, like in the first case, then folowing will happen:

  1. New sales order will be created with default selected Order type
  2. In case if you assign different order type, then default, then Acumatica will create new sales order and in cache you'll have two sales orders
  3. Upon calling save action you'll get two sales orders created in your Acumatica

No Comments

Add a Comment