Programmatically set ReadyToCalc on a OrderHed via function (SetReadyToCalc)

The crux of this is a solution to calling Erp.SalesOrderSvc.SetReadyToCalc from a custom code function not working.

A bit of background: I have been attempting to write a very basic integration to allow us to continue transaction and taking orders while kinetic is down, both for backup in the event of an issue, and for use during kinetic updates.

In doing so I have been looking for a way to bring in a new Sales Order programmatically via a REST Api call to a custom function. I decided on this approach as it keeps all the logic for building the kinetic entities within kinetic. I had initially played with the idea of having the logic in the console application which is fetching data and pushing it to kinetic, but decided bringing the logic outside of kinetic was adding extra complexity for no reason.

So I created a function in kinetic which takes in a JSON encoded string containing all the pertinent data to create the sales order, order lines, and releases. The function then calls the various functions required to set everything up onto the OrderHed dataset.

However, the method SetReadyToCalc did not seem to work. This method is called when you click on calculate taxes in the OrdersEntry but when called by the code it doesn’t do anything. There are a few references to this on here, but none of those answers working in my exact scenario (New sales order on Kinetic 2024.1) So I thought I would share what did work for anyone else who is finding the same issue.

I tried a number of things to get the call working.
Firstly I started by checking what is called by kinetic itself using the inspector, which returned a call to the SetReadyToCalc endpoint.


This was sent with a ds containing only the TaxConnectStatus and the ipOrderNum.
Setting up this exact call achieved absolutely nothing in the end. The ReadyToCalc value was still false, and no tax was calculated.

I found a few conversations on here and tried those. One of which in particular may work for others:

However, it didn’t work with my situation. The end solution:

The dark art of Buffer Copy.

  var orderHed = ds.OrderHed.FirstOrDefault();
  var updatedRow = (Erp.Tablesets.OrderHedRow)ds.OrderHed.NewRow();  
  BufferCopy.Copy(orderHed, updatedRow);
  ds.OrderHed.Add(updatedRow);  
  updatedRow.ReadyToCalc = true;
  updatedRow.RowMod = "U";  

  salesOrderSvc.MasterUpdate(
    true,
    true,
    "OrderHed",
    custNum,
    orderNum,
    false,
    out outbool,
    out outstring,
    out outstring,
    out outstring,
    out outstring,
    out outstring,
    out outstring,
    out outstring,
    out outstring,
    out outstring,
    ref ds
  );

Starting with the freshly updated complete sales order tableset, then using a buffer copy of the entire OrderHed, I was able to trigger everything required in the backend and get the sales order to display with the correct state, ready to process and with taxes calculated.

2 Likes

BeforeImage strikes again!

Netflix Seriously GIF by Stranger Things

1 Like

image

1 Like