Toggling Taxable on a Sales Order

We are are a distributor that sells to both taxable and nontaxable customers. Additionally, we use Avalara’s AvaTax service to calculate tax rates. It was a lot of work for us to charge tax to a nontaxable customer who was not reselling the merchandise.

In order to charge tax to a nontaxable customer, we had to do the following:

  1. Open the nontaxable customer
  2. Check taxable
  3. Save
  4. Create a sales order
  5. Add items
  6. Save
  7. Reopen the customer
  8. Uncheck taxable
  9. Save

Whoa! What a pain. Hope the phone never rings while I’m in the middle of this checklist.

Here’s a simple solution for you developers. First, add a couple of lines to your BeforeLoad() function in the event script deployed on sales orders. I’ll include the code later so you can cut and paste.


This adds a button in the “Items” sublist of a sales order. It looks like this.

Button under Items

If you are reading along in the code, you’ll know you need some client-side script now. So add this code to your client script deployed against sales orders. It is called directly from the new button we just added. So just add it as a function somewhere in your client script.

Client Function

Here’s a walkthrough. AvaTax adds a custom field called custbody_ava_customertaxable. This gets set when a sales order is created. It gets the customer’s tax status at the time the order is created. It is fully accessible in client scripts. I actually played around trying to set it on the server side. No luck!

So here is my code:

Server-side event script deployed on sales orders, BeforeLoad():

var itemsSublist = form.getSubList(‘item’);
itemsSublist.addButton(‘custpage_updt_exp_ship_dates’, ‘Toggle Taxable’, ‘logic_client_orders.toggleTaxable()’);
Client-side code deployed on sales orders:
toggleTaxable: function() {
var taxable = nlapiGetFieldValue(‘custbody_ava_customertaxable’);
if (!taxable) taxable =’F’;
if (taxable ==’F’) {
nlapiSetFieldValue(‘custbody_ava_customertaxable’, ‘T’);
alert(‘Is Taxable: True’);
else {
nlapiSetFieldValue(‘custbody_ava_customertaxable’, ‘F’);
alert(‘Is Taxable: False’);
One more note… I’m using JavaScript namespaces. “logic_client_orders” is my client-side namespace. You’ll want to swap that for yours or remove it.

Leave a Reply

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

You are commenting using your 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