Avalara’s Avatax Bundle in NetSuite – Demystified (Developer Notes)

I’ve been asked to investigate why our NetSuite system is making so many calls to Avalara to calculate tax. Each call costs, and we make an inordinate number of calls. These notes are mainly for me, but I’m happy to share. If anything in this post is incorrect, please feel free to comment. This is not intended to disparage Avalara, it’s simply notes about how to manage it.

First, I’ve determined that any time transactions (Estimates, Sales Orders and possibly Invoices) are saved, a web service call is made to Avalara to calculate tax. Cha Ching!

Second, and to Avalara’s credit, they offer configuration options for turning off the tax calculation on each type of transaction. So if you don’t need tax on an estimate, just turn it off. However, if you convert an estimate to a sales order, you may want the totals to match, and that requires tax.

Third, if nothing affecting the tax calculation changes, you would expect Avalara to skip the web service call. It does not! Consider this, someone copies an estimate/quote to make a revision. Nothing changes. The shipping address and all items in the quote remain 100% the same as the copied transaction. However, at that instant, the newly created copy isn’t saved until the user clicks Save, Cha Ching! If anything is changed in the transaction, like assigning a second sales rep, anything, Cha Ching! And so on, and so on, and so on. Cha Ching.

Now, here are some notes regarding how to track the web services calls. Open a transaction and save it, without changing anything. NetSuite will prompt to confirm. Say yes. Next, view the AvaTax tab. You’ll see something like this. Check the timestamps, it confirms you just made a webservice call to Avalara! If you click “More…”, you’ll see the response includes your calculated tax amount.

Developer Notes:

Avalara is installed as a bundle and associated scripts live in the file cabinet in “/SuiteBundles/Bundle 1894”.

AvaTax got an upgrade from SuiteScript 1.0 to SuiteScript 2.0 with AvaTax 7.6. If you have not upgraded your Avalara bundle in some time, you should. All code from 7.6 on which affects web services calls has been upgraded and moved to new libraries.

Reviewing Avalara code:

It’s an easy task to browse to “/SuiteBundles/Bundle 1894” and download the entire directly. It comes down as a zipped file which can be expanded and checked into source control.

In AVA_CLI_Transaction.js (the naming conventions make it very easy to find the client-side scripts that handle the Save and Calculate Tax buttons), you’ll find AVA_TransactionSave() and AVA_CalcuateOnDemand() functions. Because they are client-side calls you can evaluate these using Chrome Developer Tools.

Ultimately, calls wind up at TaxLibrary.js AVA_CalculateTax(). It is important to note that this library is not available in VIEW mode, but only in EDIT mode when setting stops in Chrome Developer tools.

And finally, here is where I stopped my research prior to writing this post, you can make a direct call to AVA_CalculateTax() from the console window of Chrome Developer Tools. It looks like this. Open a transaction in EDIT mode. Let it fully load. Then paste this into the console window of Chrome Dev Tools. You can step through the entire process of updating the tax amount, including the web services call.

Snapshot of vsCode sample call to calculate tax
require(['N/currentRecord', '/SuiteBundles/Bundle 1894/utility/AVA_TaxLibrary.js'],
    function (currentRecord, tax_lib) {
        var cRecord = currentRecord.get();
        var connectionStartTime = new Date();
        tax_lib.AVA_CalculateTaxOnDemand(cRecord, connectionStartTime);

This call appears to calculate tax and update your transation (I didn’t actually confirm that the tax amount has been updated). And, it does not log the web services call in the AvaTax tab. That remains to be investigated.

It took time to get this far and I don’t want to lose my research. Thus, this blog article. If anyone picks up here, send me a comment and perhaps you can return the favor by saving me some time. Thanks!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s