SuiteScript 2.x is built around a modular architecture. Instead of one giant API, functionality is split into focused modules that you load with define or require. Understanding which module does what is the fastest way to go from copy-paste scripting to writing clean, maintainable NetSuite customizations. This guide walks through the modules you will reach for every day, each paired with a real-world example.
1. N/record โ Creating and Editing Records
The N/record module is the backbone of almost every script. It lets you create, load, edit, submit, and delete records without touching the UI.
Real-world example: A warehouse team wants a Sales Order to automatically reserve inventory by flipping a custom checkbox the moment the order is approved.
define(['N/record'], (record) => {
const afterSubmit = (context) => {
if (context.type !== context.UserEventType.APPROVE) return;
const so = record.load({
type: record.Type.SALES_ORDER,
id: context.newRecord.id,
isDynamic: true
});
so.setValue({ fieldId: 'custbody_reserve_inventory', value: true });
so.save();
};
return { afterSubmit };
});
2. N/search โ Querying Data
Use N/search when you need to find records that match a set of criteria โ overdue invoices, low-stock items, customers in a region, and so on.
Real-world example: Finance wants a daily list of every open invoice more than 30 days past due.
define(['N/search'], (search) => {
const run = () => {
const overdue = search.create({
type: search.Type.INVOICE,
filters: [
['status', 'anyof', 'CustInvc:A'], // Open
'AND',
['daysoverdue', 'greaterthan', 30]
],
columns: ['tranid', 'entity', 'amountremaining', 'daysoverdue']
});
overdue.run().each((result) => {
log.audit('Overdue Invoice', result.getValue('tranid'));
return true; // keep iterating
});
};
return { run };
});
3. N/email โ Sending Notifications
The N/email module sends transactional emails, optionally with attachments, and logs them against a record for a full audit trail.
Real-world example: Automatically email a sales rep when one of their opportunities crosses a $50,000 threshold.
define(['N/email', 'N/runtime'], (email, runtime) => {
const notifyRep = (repId, oppId, amount) => {
email.send({
author: runtime.getCurrentUser().id,
recipients: repId,
subject: 'High-value opportunity: $' + amount,
body: 'Opportunity ' + oppId + ' just crossed $50k. Time to follow up!',
relatedRecords: { transactionId: oppId }
});
};
return { notifyRep };
});
4. N/runtime โ Context and Configuration
N/runtime tells you who is running the script, in which role, and how many governance units remain. It is essential for writing scripts that behave differently per environment or that avoid hitting usage limits.
define(['N/runtime'], (runtime) => {
const check = () => {
const script = runtime.getCurrentScript();
log.debug('Remaining governance', script.getRemainingUsage());
log.debug('Current user', runtime.getCurrentUser().name);
};
return { check };
});
5. N/https โ Talking to External Systems
Integrations live in N/https. Use it to call third-party REST APIs โ shipping carriers, payment gateways, tax engines, or your own microservices.
Real-world example: Fetch a live shipping quote from a carrier API when a fulfillment is created.
define(['N/https'], (https) => {
const getRate = (zip, weight) => {
const response = https.post({
url: 'https://api.carrier.example/v1/rates',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ destinationZip: zip, weightLb: weight })
});
return JSON.parse(response.body).rate;
};
return { getRate };
});
Quick Reference
- N/record โ create, load, edit, and delete records.
- N/search โ query records with filters and columns.
- N/email โ send emails and attach them to records.
- N/runtime โ read execution context and governance.
- N/https โ integrate with external REST APIs.
Master these five modules and you can handle the vast majority of real-world NetSuite automation. In a future post we will dig into N/task for scheduling and N/query for SuiteQL-powered reporting.
Discover more from The NetSuite Pro
Subscribe to get the latest posts sent to your email.
Leave a Reply