🔹 Introduction
Writing your first NetSuite script can feel like a big step, but once you understand the process, it becomes straightforward.
In this guide, we’ll walk you through creating a simple script and deploying it in NetSuite, so you can see your code in action.
By the end, you’ll know how to:
- Create a script file
- Upload it to the NetSuite File Cabinet
- Create a Script Record
- Deploy it on a record
🔹 Step 1: Create a Simple Script
Let’s start with a basic Client Script that shows an alert when you open a record.
Code Example (Hello World – Client Script):
/**
*@NApiVersion 2.1
*@NScriptType ClientScript
*/
define([], () => {
const pageInit = () => {
alert('Hello NetSuite! This is my first script.');
};
return { pageInit };
});
Save this file as:FirstScript.js
🔹 Step 2: Upload Script to File Cabinet
- Go to Documents → Files → File Cabinet.
- Navigate to a custom folder (e.g.,
/SuiteScripts/
). - Click Upload File and add
FirstScript.js
.
🔹 Step 3: Create Script Record
- Navigate to Customization → Scripting → Scripts → New.
- Upload the Script that was created.
- In the Script File field, select the file you uploaded.
- Give it a name (e.g., “First Client Script”).
🔹 Step 4: Deploy the Script
- In the Script record, go to the Deployments subtab.
- Click New Deployment.
- Choose where to deploy (e.g., Record Type = Customer).
- Set Status = Released.
- Save.
Now, open a Customer Record. You should see the popup:
“Hello NetSuite! This is my first script.” 🎉
🔹 Example 2: Auto-Set a Field on Deployment
Let’s make it a little more useful. This script will automatically fill the “Memo” field on a Sales Order
/**
*@NApiVersion 2.1
*@NScriptType ClientScript
*/
define(['N/currentRecord'], (currentRecord) => {
const pageInit = () => {
const rec = currentRecord.get();
rec.setValue({
fieldId: 'memo',
value: 'Created via First Script Deployment'
});
};
return { pageInit };
});
Deploy this script to Sales Order records, and the Memo will auto-populate.
🔹 Example 3: First User Event Script Deployment
Want to run something on record save instead of page load? Try this User Event Script.
/**
*@NApiVersion 2.1
*@NScriptType UserEventScript
*/
define([], () => {
const afterSubmit = (context) => {
if (context.type === context.UserEventType.CREATE) {
const newRecord = context.newRecord;
log.debug('New Record Created', `Type: ${newRecord.type}`);
}
};
return { afterSubmit };
});
Deploy this to the Customer record type.
Now, when a new customer is created, a log entry will appear in Execution Log.
🔹 Tips for Beginners
- Always test in Sandbox, not Production.
- Use log.debug() for server-side debugging.
- Keep script names + file names clear (
CustomerAutoEmail.js
,SOAutoMemo.js
). - Start small → build confidence before moving to Map/Reduce or Suitelets.
âś… Key Takeaway
Deploying your first NetSuite script is a simple 4-step process:
👉 Write code → Upload → Create Script Record → Deploy.