Understanding SuiteScript Types in NetSuite (with Examples)


SuiteScript is a JavaScript-based tool (yes, you need to know Javascript to write Suitescripts) that allows developers to customize and automate how NetSuite works. You can use SuiteScripts to change how forms behave, automate routine tasks, create new user interfaces, or even connect NetSuite with other systems.
There are two main types of SuiteScripts:
Client-side scripts – Run in the user’s browser (just one type: Client Script)
Server-side scripts – Run on NetSuite’s backend (includes types like User Event, Scheduled, Suitelet, etc.)
Let’s go through each script type in Suitescript 2.0 with a simple real-world example, so you know when to use what.
Each SuiteScript type uses special functions called “entry points.” These are the main functions that NetSuite looks for when running your script.
For example:
In a Client Script, entry points include
saveRecord
,fieldChanged
, etc.In a Scheduled Script, the entry point is usually
execute
.In the User Event Script, entry points are
beforeLoad
,afterSubmit
, etc.
In these examples, we’re only showing one entry point at a time to help you focus and understand each script's purpose without getting overwhelmed. In real projects, you might use more entry points in the same script file, but learning them one by one is the best way to start.
1. Client Script
Runs in the browser when a user fills a form. It gives instant feedback.
When to use it: To show alerts or stop form submission based on form data.
Example:
Don’t allow saving a Sales Order if the memo field is blank.
function saveRecord(context) {
var currentRecord = context.currentRecord;
var memo = currentRecord.getValue({ fieldId: 'memo' }).trim();
if (!memo) {
alert('Please write a memo for this sales order.');
return false;
}
return true;
}
2. User Event Script
Runs on the server side when a record is created, edited, or deleted.
When to use it: To set values automatically or send notifications.
Example:
Automatically assign a sales rep when a new customer is created.
function beforeSubmit(context) {
var rec = context.newRecord;
if (context.type === context.UserEventType.CREATE) {
rec.setValue({ fieldId: 'salesrep', value: 123 }); // 123 = internal ID of sales rep employee record
}
}
3. Scheduled Script
Runs on a schedule, like once a day or every hour.
When to use it: To update many records, send reports, or clean up data.
Example:
Mark all Sales Orders older than 30 days as “priority”.
function execute(context) {
var searchResult = search.load({ id: 'customsearch_old_sales_orders' }).run();
searchResult.each(function(result) {
var salesOrder = record.load({ type: record.Type.SALES_ORDER, id: result.id });
salesOrder.setValue({ fieldId: 'custbody_priority', value: true });
salesOrder.save();
return true;
});
}
4. Suitelet Script
Creates custom UI pages in NetSuite with forms, buttons, and fields.
When to use it: To build tools like search forms, dashboards, or custom workflows.
Example:
Create a form that lets users search customers by ZIP code.
function onRequest(context) {
if (context.request.method === 'GET') {
var form = serverWidget.createForm({ title: 'Customer ZIP Search' });
form.addField({ id: 'zip', type: serverWidget.FieldType.TEXT, label: 'ZIP Code' });
form.addSubmitButton({ label: 'Search' });
context.response.writePage(form);
}
}
5. RESTlet Script
Lets external systems talk to NetSuite using API calls.
When to use it: To connect NetSuite with websites, mobile apps, or other software.
Example:
Create a new customer record in NetSuite from an external app that has sent a POST request with companyName in the body.
function post(context) {
return record.create({
type: record.Type.CUSTOMER,
isDynamic: true
}).setValue({ fieldId: 'companyname', value: context.companyName }).save();
}
6. Map/Reduce Script
Processes large amounts of data in steps, using parallel processing.
When to use it: For things like mass updates, data cleanup, or generating summaries. I will share the working of the Map/Reduce script in a separate post.
Example:
Update credit limits for all customers based on their past purchases.
function map(context) { // Runs after getInputData entry point
var customer = JSON.parse(context.value);
var newLimit = calculateCreditLimit(customer.id);
context.write({ key: customer.id, value: newLimit });
}
function reduce(context) { // Runs after getInputData if map is not present
var creditLimit = parseFloat(context.values[0]);
record.submitFields({
type: record.Type.CUSTOMER,
id: context.key,
values: { creditlimit: creditLimit }
});
}
7. Portlet Script
Creates widgets on the NetSuite dashboard for real-time data or visuals.
When to use it: To show KPIs, reports, or shortcuts on users’ homepages.
Example:
Display the top 5 customers by sales this month on a dashboard.
function render(params) {
var portlet = params.portlet;
portlet.title = 'Top 5 Customers This Month';
portlet.addLine('Customer A: ₹12,000');
portlet.addLine('Customer B: ₹9,800');
}
8. Workflow Action Script
Works inside NetSuite workflows to do custom logic at specific steps.
When to use it: If you need to run a custom action during an approval or transition in a workflow.
Example:
If the total order is more than ₹50,000, set a flag as “high value”.
function onAction(context) {
var rec = context.newRecord;
var total = rec.getValue({ fieldId: 'total' });
if (total > 50000) {
rec.setValue({ fieldId: 'custbody_high_value', value: true });
}
return rec;
}
Final Thoughts
SuiteScript helps you make NetSuite do exactly what your business needs - from customising forms and automating processes to connecting with other apps.
Each script type has its purpose:
Use Client Scripts for forms
Use User Event and Scheduled Scripts for backend automation
Use Suitelets and Portlets for UI customisation
Use RESTlets to talk to outside systems
Use Map/Reduce for big data jobs
Use Workflow Action Scripts inside workflows
Start small, use one entry point at a time, and grow from there.
Subscribe to my newsletter
Read articles from Rahul Thakur directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
