Getting Started with SuiteScript 2.0: Your First Script


NetSuite's SuiteScript 2.0 is a JavaScript-based API that lets developers customize and automate almost every part of the NetSuite platform. Whether you're automating tasks, creating custom workflows, or integrating other systems, SuiteScript 2.0 is your go-to tool.
This guide is ideal for beginners looking to write their first NetSuite script. We'll walk through a real-world example that solves a business problem.
What Is SuiteScript 2.0?
SuiteScript 2.0 offers a modern, modular architecture based on AMD (Asynchronous Module Definition). It is more maintainable and scalable than SuiteScript 1.0.
In this blog, we’ll focus only on SuiteScript 2.x, which is the current and future standard.
NetSuite supports different types of scripts. (See: Types of SuiteScripts in NetSuite)
To get started, we’ll begin with a User Event Script, which runs when a record is created, updated, or deleted.
SuiteScript 2.0 Setup Checklist
Before writing your first script, let’s set up your environment:
1. Enable SuiteScript Features
Go to Setup > Company > Enable Features
Under the SuiteCloud tab:
✅ Check Client SuiteScript
✅ Check Server SuiteScript
Then, go to Home > Set Preferences, and check the Show Internal IDs box.
This is crucial for developers to find the field and record IDs.
2. Verify Role Permissions
Make sure your role has these permissions:
Script – Full
Script Deployment – Full
File Cabinet – Full
3. Locate Script Management
Go to Customization > Scripting > Scripts to manage your scripts.
4. Use a Proper Code Editor
It’s best to use editors like VS Code, WebStorm, or Sublime Text for syntax highlighting and version control.
Tip: Always test your scripts in a Sandbox account before deploying them in production.
Real-World Use Case:
Problem Statement
When an invoice is created, the due date should be automatically set to the last day of the same month as the invoice date.
Example:
If Invoice Date = July 10, 2025
Then Due Date should auto-set to July 31, 2025
Why Use a User Event Script?
You need to calculate the due date dynamically when the record is created
You need to set the value before the record is saved
So, a User Event Script with abeforeSubmit
function is the best fit.
The User Event Script
/**
*@NApiVersion 2.0
*@NScriptType UserEventScript
*/
define(['N/record', 'N/log'], function(record, log) {
function beforeSubmit(context) {
if (context.type !== context.UserEventType.CREATE) return;
var invoice = context.newRecord;
var invoiceDate = invoice.getText({ fieldId: 'trandate' });
log.debug("Invoice Date", invoiceDate);
var dateObj = new Date(invoiceDate);
var lastDay = new Date(dateObj.getFullYear(), dateObj.getMonth() + 1, 0);
invoice.setValue({fieldId: 'duedate', value: lastDay});
}
return { beforeSubmit };
});
Script Explanation (Simplified)
@NApiVersion
tells NetSuite we’re using SuiteScript 2.0.define()
is used to load required modules likeN/record
andN/log
.The script uses the beforeSubmit event so we can modify the record before it’s saved.
context.type !== CREATE
ensures the script only runs on new invoices.trandate
is the internal ID of the Invoice Date field.We calculate the last day of the month using JavaScript and set it as the due date.
No need to save the record manually – NetSuite handles that after the
beforeSubmit
function.
How to Deploy This Script in NetSuite
1. Upload Script
Go to: Customization > Scripting > Scripts > New
Click the + icon to upload your
.js
script file from your computer.The file will go to the default SuiteScripts folder (you can change it).
2. Create Script Record
After uploading, click Create Script Record
NetSuite will auto-detect the script type and version.
Fill in the Name and optional ID, then click Save and Deploy
3. Deploy the Script
On the deployment screen:
Select Invoice in the Applies To field
Set Status to
Testing
Check Deployed
Set Log Level to
Debug
(to help with testing)Save the deployment
Check the Audience subtab to choose roles, subsidiaries, departments, etc, for which the script should execute.
Testing Your Script
Create a new Invoice
Leave the Due Date field empty
Save the record
The Due Date should auto-fill to the last day of that month
If it doesn’t work, check the Execution Log under your script deployment for any errors.
Final Tips
Use
log.debug()
to help troubleshoot your scriptAlways test in Sandbox before moving to production
Use clear script and deployment IDs for better tracking
💬 Questions?
Drop your questions in the comments. I’ll be happy to help!
Happy SuiteScripting!
Subscribe to my newsletter
Read articles from Rahul Thakur directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
