This is a working reference for developers actively migrating scripts from SuiteScript 1.0 to 2.1. Bookmark it. The single most important pattern to internalize before you start: SuiteScript 1.0 uses global nlapi functions with positional arguments, while 2.1 uses loaded modules with named object parameters. Once that shift clicks, most of the migration becomes mechanical. For the authoritative, exhaustive reference, keep Oracle’s SuiteScript 1.0 to SuiteScript 2.1 API Map open alongside this cheat sheet.
Every 2.1 script begins by declaring the modules it needs. Throughout the examples below, assume the relevant module has been loaded (for example N/record, N/search, N/email).
1. Record operations
nlapiLoadRecord, nlapiCreateRecord, nlapiSubmitRecord, and nlapiDeleteRecord all map to the N/record module. The key change: positional arguments become a single options object with named keys such as type and id.
// 1.0 - positional
var rec = nlapiLoadRecord('salesorder', 123);
var id = nlapiSubmitRecord(rec);
// 2.1 - named params
var rec = record.load({ type: record.Type.SALES_ORDER, id: 123 });
var id = rec.save();
// create / delete
var so = record.create({ type: record.Type.SALES_ORDER });
record.delete({ type: record.Type.SALES_ORDER, id: 123 });
2. Field operations
nlapiGetFieldValue, nlapiSetFieldValue, and line-item getters like nlapiGetLineItemValue become methods on a record object. In client scripts, the record in context comes from the N/currentRecord module (or the record passed into an entry point).
// 1.0
var status = nlapiGetFieldValue('orderstatus');
nlapiSetFieldValue('memo', 'Reviewed');
var qty = nlapiGetLineItemValue('item', 'quantity', 1);
// 2.1
var rec = currentRecord.get();
var status = rec.getValue({ fieldId: 'orderstatus' });
rec.setValue({ fieldId: 'memo', value: 'Reviewed' });
var qty = rec.getSublistValue({ sublistId: 'item', fieldId: 'quantity', line: 0 });
Note two shifts at once: named params, and 2.1 sublist lines are zero-indexed (line 0 is the first line) versus 1.0’s 1-based indexing.
3. Search
nlapiSearchRecord and nlapiCreateSearch map to N/search. You build a search with search.create() and read results with run().getRange() (or each() / paged results for larger sets).
// 1.0
var results = nlapiSearchRecord('customer', null,
new nlobjSearchFilter('email', null, 'is', 'x@y.com'));
// 2.1
var results = search.create({
type: search.Type.CUSTOMER,
filters: [['email', 'is', 'x@y.com']],
columns: ['entityid', 'email']
}).run().getRange({ start: 0, end: 1000 });
4. Email
nlapiSendEmail becomes N/email‘s email.send() – a textbook positional-to-named conversion.
// 1.0
nlapiSendEmail(-5, 'to@x.com', 'Subject', 'Body');
// 2.1
email.send({
author: -5,
recipients: 'to@x.com',
subject: 'Subject',
body: 'Body'
});
5. Runtime context
nlapiGetContext, nlapiGetUser, and related environment calls consolidate into the N/runtime module.
// 1.0
var ctx = nlapiGetContext();
var userId = nlapiGetUser();
var role = ctx.getRole();
// 2.1
var userId = runtime.getCurrentUser().id;
var role = runtime.getCurrentUser().role;
var env = runtime.envType;
6. Logging
nlapiLogExecution is replaced by the built-in global log object, whose methods encode the severity: log.debug, log.audit, log.error, and log.emergency.
// 1.0
nlapiLogExecution('DEBUG', 'Title', 'Details');
// 2.1
log.debug({ title: 'Title', details: 'Details' });
log.audit({ title: 'Saved', details: id });
log.error({ title: 'Failed', details: e.message });
7. HTTP requests
nlapiRequestURL maps to the N/https module (use N/http for non-secure, but prefer https). Methods like https.get() and https.post() take named params.
// 1.0
var resp = nlapiRequestURL('https://api.x.com', postData, headers);
// 2.1
var resp = https.post({
url: 'https://api.x.com',
body: postData,
headers: headers
});
var body = resp.body;
var code = resp.code;
8. Sublist and subrecord operations – the biggest change
This is where migrations get the most involved. In 1.0 you manipulated lines with functions like nlapiSelectNewLineItem, nlapiSetCurrentLineItemValue, and nlapiCommitLineItem. In 2.1 you choose between two explicit modes: standard mode (direct setSublistValue by line index) and dynamic mode (selectNewLine / setCurrentSublistValue / commitLine). You must decide which mode a record is in when you load or create it.
// 1.0 (implicitly dynamic)
nlapiSelectNewLineItem('item');
nlapiSetCurrentLineItemValue('item', 'item', 200);
nlapiCommitLineItem('item');
// 2.1 standard mode
rec.setSublistValue({ sublistId: 'item', fieldId: 'item', line: 0, value: 200 });
// 2.1 dynamic mode (load/create with isDynamic: true)
rec.selectNewLine({ sublistId: 'item' });
rec.setCurrentSublistValue({ sublistId: 'item', fieldId: 'item', value: 200 });
rec.commitLine({ sublistId: 'item' });
Subrecords (like the address or inventory detail) are similarly accessed through explicit methods such as getSubrecord() rather than the old nlapiViewCurrentLineItemSubrecord style calls. Budget extra testing time here – this category produces the most subtle behavioral differences.
9. APIs with no direct mapping
A handful of 1.0 calls have no one-to-one 2.1 replacement. Rather than searching for an equivalent function, you use a different approach:
- UI object builders (the old
nlobjForm,nlobjListstyle) move to the N/ui/serverWidget module, with a different construction pattern. - Some date/format helpers are replaced by the N/format module plus native JavaScript, instead of
nlapiStringToDatestyle wrappers. - Certain utility globals map into modules like N/util, N/config, or N/redirect depending on purpose.
When you hit a call with no obvious equivalent, do not force it – consult Oracle’s API Map, which explicitly lists the unmapped functions and the recommended alternative for each.
The one rule to remember
If you internalize a single principle from this sheet, make it this: positional arguments become named object parameters, and global functions become module methods. Load the module, call the method, pass an options object. Almost everything else is detail. For the complete, always-current mapping – including every function this cheat sheet condenses – bookmark Oracle’s official SuiteScript 1.0 to SuiteScript 2.1 API Map.
Discover more from The NetSuite Pro
Subscribe to get the latest posts sent to your email.
Leave a Reply