Stumped on SalesOrder.MasterUpdate and calculating Tax

I have a Function that receives a json dataset and creates Sales Orders. One of the steps is to calculate Tax via Avalara, which is done by toggling the ReadyToCalc field and calling a MasterUpdate:

Basically this is the same thing we do in the UI… Checking the box and saving automatically calculates tax; we don’t have to go to Actions → Calculate Tax (although we can).

The code works to set the field to true, but oddly it is only actually calculating Tax on the Sales Order if this chunk of code to add a Misc Charge fires beforehand:

In other words, my code is not currently working if there is no freight charge on the order… Something about that OHOrderMsc MasterUpdate call seems to make it work.

I’ve seen some weird stuff developing in Epicor over the years, but this one has me stumped. I can probably throw in an extra GetByID and/or MasterUpdate to get it working, but am trying to understand the why or if I’m doing something wrong here… I welcome any advice!

1 Like

My guess is that it’s a combination of things:

  1. You are setting ReadyToCalc == true but your OrderRel table doesn’t have any updated rows (Taxes are added to order releases)
  2. You aren’t calling SalesOrderSvc.SetReadyToCalc(iOrderNum, ref ts), which adds and updated row to the TsSalesOrder.TaxConnectStatus table.

If you had an updated row in your releases (or apparently your OHOrderMsc), it will add the TaxConnectStatus row with RowMod=="U" automatically. Since that isn’t the case, it appears to be skipping that bit.

1 Like

I think if you add this bit below to your code after you set the rowHed.ReadyToCalc = true;, it will work without the misc charge:

foreach (var rowTax in TsSalesOrder.TaxConnectStatus)
{
    rowTax.RowMod = "U";
    rowTax.ETCOffline = false;
    TCStatus = true;
}

P.S. what is your code editor theme? I like that one.

1 Like

Do you have an unmodified row and a modified row?

2 Likes

If he’s getting the TableSet using GetByID, it should only have one row, so setting the RowMod to “U” should be fine.

Your point is well taken though, if that throws an error it might need to use the BufferCopy trick.

1 Like

Not if he changes a field.

Tom, try copying the row, and change the copy.

2 Likes

#BeforeImage

3 Likes

doctor guys GIF

1 Like

Yep, #BeforeImage strikes again!

Lol I can’t believe I forgot the golden rule… when in doubt use BufferCopy. Are you guys just BufferCopy’ing everything by default these days? I feel like I should just start doing that.

Here is the working snippet for anyone interested:

Thank you Kevins and Jose.

@kve , it looks like editor color theme is “Dark Modern” (VS Code)

1 Like

I had tried that too but got the same behavior before fixing issue with BufferCopy. I may still throw that method call in for good measure though.

Still weird that the original code worked if a freight misc charge was added to the order… I’m guessing that MasterUpdate jiggled the dataset in a way that didn’t need BufferCopy to resolve.

Honestly we always should we are lazy but Epicor expects every server side call to come with a BI for any modified datasets

3 Likes