SuiteScript 1.0 to 2.1 reference
nlapiGetContext in SuiteScript 2.1
In SuiteScript 2.1, nlapiGetContext is replaced by runtime.getCurrentScript / runtime.getCurrentUser from N/runtime. Reads script parameters, remaining governance and the current user.
Before and after
// SuiteScript 1.0
var ctx = nlapiGetContext();
var param = ctx.getSetting('SCRIPT', 'custscript_limit');
var left = ctx.getRemainingUsage();
var user = ctx.getUser();// SuiteScript 2.1
define(['N/runtime'], (runtime) => {
const script = runtime.getCurrentScript();
const param = script.getParameter({ name: 'custscript_limit' });
const left = script.getRemainingUsage();
const user = runtime.getCurrentUser().id;
});What to watch for
- 1.0's single context object is split between the script, the user and the session.
- nlapiGetUser() becomes runtime.getCurrentUser().id.
Related functions
- nlapiScheduleScript becomes task.create
- nlapiYieldScript becomes Map/Reduce script
- nlapiSendEmail becomes email.send
- All SuiteScript 1.0 functions
Find what still needs converting
Find every script that still calls nlapiGetContext
SuiteMigrate lists the active 1.0 and 2.0 scripts in your NetSuite account, shows which ones you can read and which are locked, and drafts 2.1 conversions you review before deploying. Free for 5 conversions.
Examples are simplified. Test converted code in a NetSuite sandbox before deploying. SuiteMigrate is not affiliated with Oracle or NetSuite.