Disable Tax Fields
This customization is designed for accounts that use Legacy Tax (accounts where the SuiteTax feature is not enabled).
The script in this tutorial disables tax fields on U.S. sales transactions only. The script is created with the assumption that the Per Line Taxes on Transaction preference is not enabled for U.S. and the tax fields appear as transaction body fields on the Accounting subtab of the transaction record. For information about U.S. tax preferences, see Setting U.S. Tax Preferences.
This customization shows how to control who can edit tax fields on the following sales transactions: Cash Refund, Cash Sale, Credit Memo, Invoice, Sales Order, and Return Authorization.
Only the Administrator and users logged in using specific roles will have permission to edit tax fields. The sales transaction will be created as normal, and taxation will depend on how the customer and items are set up.
This customization uses a script parameter to determine which roles can edit tax fields. If the user is logged in with a role that is not an Administrator or a role that is not specified in the parameter, the script disables the tax fields. This is independent of whether the sale is taxable or not.
The script in this tutorial disables the following tax fields for U.S. sales transactions:
Field Name |
Field Type |
Internal ID |
Location |
---|---|---|---|
Taxable |
Checkbox |
istaxable |
Accounting subtab > Tax information field group |
Tax Item |
Select |
taxitem |
Accounting subtab > Tax information field group |
Tax Rate |
Float |
taxrate |
Accounting subtab > Tax information field group |
This project is available on the SuiteCloud Project Repository on Oracle Samples GitHub and include complete project customization setup with custom objects, unit tests, package file configuration, and more.
Customization Details
The customization for this use case includes:
-
A script parameter (Tax Allowlist) to specify which roles are allowed to modify the tax fields on the transaction record
-
A client script triggered on the pageInit entry point
Steps in this tutorial to complete this customization:
Before You Begin
The following table lists features, permissions, and other requirements necessary for performing this tutorial and implementing the solution:
Required Features |
The following features must be enabled in your account:
For more information, see Enabling Features.
Note:
This tutorial deals with subsidiaries. You will need a NetSuite OneWorld account which automatically includes support for subsidiaries. |
Required Permissions |
You will need a role with access to the following:
For more information, see NetSuite Permissions Overview. |
Other Requirements |
None |
Step 1: Write the Script
This script reads the value of a script parameter to determine if the user can edit tax fields on a U.S. sales transaction.
Script Summary
The following table summarizes the script:
Script: Disable Tax Fields |
|
---|---|
Script Type |
|
Modules Used |
|
Entry Points |
For more information about script types and entry points, see SuiteScript 2.x Script Types.
The Complete Script
This tutorial includes the complete script along with individual steps you can follow to build the script in logical sections. The complete script is provided below so that you can copy and paste it into your text editor and save the script as a .js file (for example, cs_disableTaxFields.js).
If you would rather create your script by adding code in logical sections, follow the steps in Build the Script.
This tutorial script uses the define
function, which is required for an entry point script (a script you attach to a script record and deploy). You must use the require
function if you want to copy the script into the SuiteScript Debugger and test it. For more information, see SuiteScript Debugger.
This sample uses SuiteScript 2.1. For more information, see SuiteScript 2.1.
/**
* @NApiVersion 2.1
* @NScriptType ClientScript
* @NModuleScope SameAccount
*/
define(['N/runtime', 'N/log'], (runtime, log) => {
function pageInit (scriptContext) {
try {
const objRecord = scriptContext.currentRecord;
const stRecordType = objRecord.type;
const stFuncName = '_DisableTaxField_' + stRecordType;
if (scriptContext.mode !== 'copy') {
const objContext = runtime.getCurrentScript();
const stAllowList = objContext.getParameter({
name: 'custscript_tax_allowlist'
});
const stUserRole = runtime.getCurrentUser().role;
const arrExclusionRoleList = stAllowList.split(',');
if (NSUtil.isEmpty(stAllowList)) {
log.error({
title: stFuncName,
details: 'Script parameter is empty. Script will now exit'
});
return
}
const taxitem = objRecord.getField({
fieldId: 'taxitem'
});
if (taxitem && !NSUtil.inArray(stUserRole, arrExclusionRoleList)) {
const istaxable = objRecord.getField({
fieldId: 'istaxable'
});
const taxrate = objRecord.getField({
fieldId: 'taxrate'
});
istaxable.isDisabled = true;
taxitem.isDisabled = true;
taxrate.isDisabled = true;
}
}
} catch (error) {
if (error !== undefined) {
log.error({
title: 'Process Error in pageInit',
details: error
});
throw error;
}
}
}
return {
pageInit: pageInit
};
});
const NSUtil = {
isEmpty: function (stValue) {
if ((stValue === '') || (stValue === null) || (stValue === undefined)) {
return true;
}
},
inArray: function (stValue, arrValue) {
let bIsValueFound = false;
for (let i = arrValue.length; i >= 0; i--) {
if (stValue == arrValue[i]) {
bIsValueFound = true
break;
}
}
return bIsValueFound;
}
}
Build the Script
You can write the script using a step-by-step approach that includes the following:
The code snippets included below do not account for indentation. Refer to The Complete Script for suggested indentation.
Start with required opening lines
JSDoc comments and a define
function are required at the top of the script file. The JSDoc comments in this script indicate that it is a SuiteScript 2.x (2.0 or 2.1) client script. The script uses two SuiteScript modules specified in the define
statement:
-
N/runtime
-provides access to runtime information including script parameters -
N/log
– allows you to log execution details
Start a new script file using any text editor and place the following JSDoc comments and define
function at the top of the file:
This tutorial script uses the define
function, which is required for an entry point script (a script you attach to a script record and deploy). You must use the require
function if you want to copy the script into the SuiteScript Debugger and test it. For more information, see SuiteScript Debugger.
/**
* @NApiVersion 2.1
* @NScriptType ClientScript
* @NModuleScope SameAccount
*/
define(['N/runtime', 'N/log'], (runtime, log) => {
});
Create the entry point functions
This script is triggered on the pageInit
entry point when a sales transaction (specifically cash refunds, cash sales, cash memos, invoices, sales orders, and return authorizations) is created or edited. A try-catch block is used to log any errors that might occur during script execution in the entry point function. Most of the script code will be placed in one of the try blocks.
Add the following entry point function definitions and initial try-catch block statements at the top of the define
function:
function pageInit(scriptContext) {
try {
} catch(error) {
if (error !== undefined) {
log.error({
title: 'Process Error in pageInit,
details: error
});
throw error;
}
}
}
Complete the pageInit function
Add the following code at the top of the try block of the pageInit
function:
const objRecord = scriptContext.currentRecord;
const stRecordType = objRecord.type;
const stFuncName = 'pageInit_DisableTaxFields_' + stRecordType;
If the transaction is in create or edit mode, we want to get the script parameter and user role information.
Add the following code within the try block of the pageInit
function:
if (scriptContext.mode !== 'copy') {
const objContext = runtime.getCurrentScript()
const stAllowList = objContext.getParameter({
name: 'custscript_tax_allowlist'
});
const stUserRole = runtime.getCurrentUser().role;
const arrExclusionRoleList = stAllowList.split(',');
If the script parameter allow list parameter is empty, we need to log an error.
Add the following code within the try block of the pageInit
function:
if (NSUtil.isEmpty(stAllowList)) {
log.error({
title: stFuncName,
details: 'Script parameter is empty. Script will now exit'
});
return
}
We will disable fields according to the US subsidiary of the customer on the transaction record. To accomplish this, we will check if the tax item field exists when a customer is selected. If the tax item field exists and the user role does not match the allow list parameter, we will disable the Taxable, Tax Item, and Tax Rate fields.
Add the following code within the try block of the pageInit
function:
const taxitem = objRecord.getField({
fieldId: 'taxitem'
});
if (taxitem && !NSUtil.inArray(stUserRole, arrExclusionRoleList)) {
const istaxable = objRecord.getField({
fieldId: 'istaxable'
});
const taxrate = objRecord.getField({
fieldId: 'taxrate'
});
istaxable.isDisabled = true;
taxitem.isDisabled = true;
taxrate.isDisabled = true;
}
The pageInit
function should now be complete.
Create the return statement
This script associates the pageInit
function to the pageInit
entry point.
Add the following code immediately above the closing });
in your script:
return {
pageInit: pageInit
};
Add the utility functions
A utility function is used to evaluate the script parameters and compare them to the user’s role and the subsidiary of the transaction.
Add the following code at the end of your script following the end of the define
function.
const NSUtil = {
isEmpty : function(stValue) {
if ((stValue === '') || (stValue === null) || (stValue === undefined)) {
return true;
}
},
inArray : function(stValue, arrValue) {
let bIsValueFound = false;
for (let i = arrValue.length; i >= 0; i--) {
if (stValue == arrValue[i]) {
bIsValueFound = true;
break;
}
}
return bIsValueFound;
}
}
Save your script file
You need to save your script file so you can load it to the NetSuite File Cabinet. Before you save your script file, you may want to adjust the indentation so that the script is readable. Refer to The Complete Script for suggested indentation.
When you are happy with how your script file reads, save it as a .js file (for example, cs_disableTaxFields.js).
Step 2: Create the Script Record
Now that you’ve completed the script, you can upload the script file to the File Cabinet and create a script record for it.
For more information about creating script records, see Creating a Script Record.
To create the script record:
-
Upload your script to the NetSuite File Cabinet.
-
Go to Customization > Scripting > Scripts > New.
-
Select your script from the Script File list and click Create Script Record. The Script page appears.
-
On the Script page, enter the following values:
Field
Value
Name
Disable Tax Fields
ID
_cs_disable_tax_fields
NetSuite prepends ‘customscript’ to this ID.
Description
This script disables tax fields on a transaction record and makes sure that only users logged in with an Administrator role or with one of the roles specified in the script parameter are allowed to edit tax fields.
-
Optionally, set any other fields on the script record as desired.
-
Click Save and Deploy. The Script Deployment page appears. Continue with Step 3: Deploy the Script.
Step 3: Deploy the Script
After you create the script record for your script, you can create a script deployment record for it. A script deployment record determines how, when, and for whom the script runs. For this tutorial, we will create multiple deployments, one for each of the following sales transactions:
For more information about script deployment records, see Script Deployment.
Cash Refund
Follow this procedure to deploy the script on cash refund transactions.
To deploy the script on cash refund transactions:
-
Go to Customization > Scripting > Scripts and click Deployments for the script record you created in Step 2: Create the Script Record).
-
Click New Deployment.
-
On the Script Deployment page, enter the following values:
Field
Value
Applies To
Cash Refund
ID
_cs_disable_tax_fields_cr
NetSuite prepends 'custdeploy' to this ID.
Status
Testing
The Testing status allows the script owner to test the script without affecting other users in the account.
Log Level
Debug
The Debug level will write all
log.debug
statements in the script to the Execution Log tab of the script deployment record as well as all errors.Audience > Internal Roles
Check Select All
Audience > External Roles
Select all external roles.
-
Click Save.
Cash Sale
Follow this procedure to deploy the script on cash sale transactions.
To deploy the script on cash sale transactions:
-
Go to Customization > Scripting > Scripts and click Deployments for the script record you created in Step 2: Create the Script Record).
-
Click New Deployment.
-
On the Script Deployment page, enter the following values:
Field
Value
Applies To
Cash Sale
ID
_cs_disable_tax_fields_cs
NetSuite prepends 'custdeploy' to this ID.
Status
Testing
The Testing status allows the script owner to test the script without affecting other users in the account.
Log Level
Debug
The Debug level will write all
log.debug
statements in the script to the Execution Log tab of the script deployment record as well as all errors.Audience > Internal Roles
Check Select All
Audience > External Roles
Select all external roles.
-
Click Save.
Credit Memo
Follow this procedure to deploy the script on credit memo transactions.
To deploy the script on credit memo transactions:
-
Go to Customization > Scripting > Scripts and click Deployments for the script record you created in Step 2: Create the Script Record).
-
Click New Deployment.
-
On the Script Deployment page, enter the following values:
Field
Value
Applies To
Credit Memo
ID
_cs_disable_tax_fields_cm
NetSuite prepends 'custdeploy' to this ID.
Status
Testing
The Testing status allows the script owner to test the script without affecting other users in the account.
Log Level
Debug
The Debug level will write all
log.debug
statements in the script to the Execution Log tab of the script deployment record as well as all errors.Audience > Internal Roles
Check Select All
Audience > External Roles
Select all external roles.
-
Click Save.
Invoice
Follow this procedure to deploy the script on invoice transactions.
To deploy the script on invoice transactions:
-
Go to Customization > Scripting > Scripts and click Deployments for the script record you created in Step 2: Create the Script Record).
-
Click New Deployment.
-
On the Script Deployment page, enter the following values:
Field
Value
Applies To
Invoice
ID
_cs_disable_tax_fields_in
NetSuite prepends 'custdeploy' to this ID.
Status
Testing
The Testing status allows the script owner to test the script without affecting other users in the account.
Log Level
Debug
The Debug level will write all
log.debug
statements in the script to the Execution Log tab of the script deployment record as well as all errors.Audience > Internal Roles
Check Select All
Audience > External Roles
Select all external roles.
-
Click Save.
Sales Order
Follow this procedure to deploy the script on sales order transactions.
To deploy the script on sales order transactions:
-
Go to Customization > Scripting > Scripts and click Deployments for the script record you created in Step 2: Create the Script Record).
-
Click New Deployment.
-
On the Script Deployment page, enter the following values:
Field
Value
Applies To
Sales Order
ID
_cs_disable_tax_fields_so
NetSuite prepends 'custdeploy' to this ID.
Status
Testing
The Testing status allows the script owner to test the script without affecting other users in the account.
Log Level
Debug
The Debug level will write all
log.debug
statements in the script to the Execution Log tab of the script deployment record as well as all errors.Audience > Internal Roles
Check Select All
Audience > External Roles
Select all external roles.
-
Click Save.
Return Authorization
Follow this procedure to deploy the script on return authorization transactions.
To deploy the script on return authorization transactions:
-
Go to Customization > Scripting > Scripts and click Deployments for the script record you created in Step 2: Create the Script Record).
-
Click New Deployment.
-
On the Script Deployment page, enter the following values:
Field
Value
Applies To
Return Authorization
ID
_cs_disable_tax_fields_ra
NetSuite prepends 'custdeploy' to this ID.
Status
Testing
The Testing status allows the script owner to test the script without affecting other users in the account.
Log Level
Debug
The Debug level will write all
log.debug
statements in the script to the Execution Log tab of the script deployment record as well as all errors.Audience > Internal Roles
Check Select All
Audience > External Roles
Select all external roles.
-
Click Save.
To verify that you have six deployments:
-
Go to Customization > Scripting > Scripts and click Deployments for the script record you created in Step 2: Create the Script Record).
-
Verify all six script deployments are listed:
-
custdeploy_cs_disable_tax_fields_cr
-
custdeploy_cs_disable_tax_fields_cs
-
custdeploy_cs_disable_tax_fields_cm
-
custdeploy_cs_disable_tax_fields_in
-
custdeploy_cs_disable_tax_fields_so
-
custdeploy_cs_disable_tax_fields_ra
-
Step 4: Create and Set the Script Parameters
This script uses a script parameter to specify which roles can edit tax fields on a transaction record.
For more information about creating and setting script parameters, see Creating Script Parameters (Custom Fields).
To create the script parameters:
-
Go to Customization > Scripting > Scripts.
-
Locate your script in the list of scripts and click Edit next to the script name.
-
On the Script page, click the Parameters tab and click New Parameter. The Script Field page appears.
-
On the Script Field page, enter the following values:
Label
ID
Type
Description
Preference
Tax Allowlist
_tax_allowlist
NetSuite prepends ‘custscript’ to this ID. The value ‘custscript_tax_allowlist’ is used in the script.
Free-Form Text
This parameter determines which roles can edit tax fields on sales transactions.
Leave blank.
-
Click Save to save the script record with the updated script parameter.
After you create the script parameters, you must set the value for each parameter on each script deployment record that you created in Step 3.
To set the script parameter:
-
Go to Customization > Scripts > Script Deployments.
-
For each script deployment:
-
Click Edit next to the deployment ID.
-
Click the Parameters subtab.
-
Enter the value for the script parameter on each script deployment record:
Deployment Record
Tax Allowlist script parameter
custdeploy_cs_disable_tax_fields_cr
3 (this is the internal ID of the Administrator role)
Add internal IDs of other roles that are allowed to edit tax fields on sales transactions, separated by commas. For example: 3,1,1001
custdeploy _cs_disable_tax_fields_cs
custdeploy _cs_disable_tax_fields_cm
custdeploy _cs_disable_tax_fields_in
custdeploy _cs_disable_tax_fields_so
custdeploy _cs_disable_tax_fields_ra
-
-
Click Save. Repeat these steps for each script deployment record.
For more information about creating script parameters, see Creating Script Parameters (Custom Fields).
Step 5: Test the Solution
After you create the script record and deploy your script, you can test your solution for two main cases:
-
Create a sales transaction with a role that is allowed to edit tax fields
-
Create a sales transaction with any other role that has Edit access to sales transactions
To test the solution for a role that is allowed to edit tax fields:
-
Log in with a role specified in the script parameter.
-
Go to Transaction > Sales > Enter Sales Orders to create a new sales order.
-
In the Customer field, select a U.S. customer.
-
On the Items subtab, select an item.
-
On the Accounting subtab, verify that the following tax fields are editable and set the values for these fields:
-
Taxable
-
Tax Item
-
Tax Rate
-
-
Click Save.
-
Edit the sales order that you created in the previous step. Verify that tax fields are still editable on edit mode.
To test the solution for a role that is not allowed to edit tax fields:
-
Log in with a role that is not specified in the script parameter. Make sure that the role has permission to edit sales transactions.
-
Go to Transaction > Sales > Enter Sales Orders to create a new sales order.
-
In the Customer field, select a U.S. customer.
-
On the Items subtab, select an item.
-
On the Accounting subtab, verify that the following tax fields are not editable:
-
Taxable
-
Tax Item
-
Tax Rate
-
-
If the subsidiary or customer is set up with default tax values, you should be able to save the sales order. Click Save.
-
Edit the sales order that you created in the previous step. Verify that tax fields are still editable on edit mode.
Related Topics
- SuiteCloud Customization Tutorials
- Add Custom Button to Execute a Suitelet
- Calculate Commission on Sales Orders
- Copy a Value to the Item Column
- Hide a Column in a Sublist
- Populate Item Substitution
- Set a Default Posting Period in a Custom Field
- Set Purchase Order Exchange Rate
- Set the Item Amount to Zero for Marketing Orders
- Set Default Values in a Sublist
- Track Customer Deposit Balances
- Validate Order on Entry