SuiteScript 2.x is NetSuiteās JavaScript-based API framework, enabling full customization and automation within NetSuite.
1. Common Script Types
Script Type Trigger Point Use Case Example
Client Script Browser/UI Validate field input in real time
User Event Script Before/After Record Save Enforce custom business rules
Suitelet On Demand Build custom UI pages or forms
Scheduled Script Timed Execution Nightly reports or data cleanup
Map/Reduce Script Asynchronous/Bulk Process thousands of transactions efficiently
RESTlet API Endpoint Integrate external systems via REST
2. SuiteScript Best Practices
Always use try…catch for error handling.
Use governance APIs to check script usage (runtime.getCurrentScript().getRemainingUsage()).
Modularize code using separate helper libraries.
Log critical operations using the log module for debugging.
Test in Sandbox before deploying to Production.
3. Example: Simple User Event Script
/**
* @NApiVersion 2.1
* @NScriptType UserEventScript
*/
define([‘N/record’, ‘N/log’], (record, log) => {
const beforeSubmit = (context) => {
const rec = context.newRecord;
if (!rec.getValue(‘entity’)) {
throw ‘Customer is required before saving the transaction.’;
}
};
return { beforeSubmit };
});