๐น 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.
Leave a Reply