Guide
SuiteScript 2.0 to 2.1 errors: why scripts break after changing @NApiVersion
From NetSuite 2028.1, SuiteScript 2.0 and 2.x server scripts run under the 2.1 runtime by default. Most keep working. The ones that fail usually fail for one of the reasons below, and only when the script runs, so test in a sandbox with the 2.1 runtime preference switched on first.
ReferenceError: variable is not defined
SuiteScript 2.1 runs in strict mode. Assigning to a variable that was never declared used to create a global; now it throws.
// fails under 2.1
function beforeSubmit(context) {
total = 0; // no var
}// works under 2.1
const beforeSubmit = (context) => {
let total = 0;
};TypeError: cannot read property of undefined (this)
In strict mode, this is undefined inside a plain function call. Code that stored state on this as a shortcut to the global object fails.
// fails under 2.1
function helper() {
this.cache = this.cache || {};
}// works under 2.1
const cache = {};
const helper = () => {
// use the module-level cache
};SyntaxError: unexpected reserved word
Names such as let, static, yield, package, interface, implements, private, protected and public are reserved in strict mode. A variable or parameter with one of these names stops the whole script from loading.
// fails under 2.1
var package = rec.getValue({ fieldId: 'custbody_pkg' });// works under 2.1
const pkg = rec.getValue({ fieldId: 'custbody_pkg' });INVALID_FLD_VALUE after search.lookupFields
lookupFields returns select fields as an array of { value, text }. Passing that array to setValue is rejected when the record is saved.
// fails under 2.1
var terms = search.lookupFields({ type: 'customer', id: id, columns: ['terms'] }).terms;
rec.setValue({ fieldId: 'terms', value: terms });// works under 2.1
const { terms } = search.lookupFields({ type: 'customer', id, columns: ['terms'] });
rec.setValue({ fieldId: 'terms', value: terms[0] ? terms[0].value : '' });Dates in the wrong format
2.1 runs on a different JavaScript engine, and Date.toString() and toLocaleDateString() output can differ. Code that parses or builds date strings by hand breaks quietly.
// fails under 2.1
var s = new Date().toLocaleDateString();// works under 2.1
const s = format.format({ value: new Date(), type: format.Type.DATE });A safer order of work
- List the active 2.0 scripts first. Here is how.
- Turn on the 2.1 runtime preference in a sandbox and run the real business flows.
- Fix what throws, then change @NApiVersion to 2.1 script by script.
- For 1.0 scripts, use the function reference or the full migration guide.
Find what still needs converting
Know which scripts to test first
SuiteMigrate lists every active 1.0 and 2.0 script in your account and marks which ones you can read. It also drafts 2.1 conversions with these issues flagged for review.