SuiteScript 1.0 to 2.1 reference

nlapiYieldScript in SuiteScript 2.1

In SuiteScript 2.1, nlapiYieldScript is replaced by Map/Reduce script from N/task or a Map/Reduce script type. Pausing a scheduled script to reset governance has no direct 2.x equivalent.

Before and after

// SuiteScript 1.0
if (nlapiGetContext().getRemainingUsage() < 100) {
  nlapiYieldScript();
}
// SuiteScript 2.1
/**
 * @NApiVersion 2.1
 * @NScriptType MapReduceScript
 */
define(['N/search'], (search) => {
  const getInputData = () => search.load({ id: 'customsearch_to_process' });
  const map = (context) => {
    const row = JSON.parse(context.value);
    // process one result; governance is per map invocation
  };
  return { getInputData, map };
});

What to watch for

  • Map/Reduce handles governance, yielding and retries per stage.
  • If a rewrite is not possible yet, a scheduled script can re-queue itself with task.create before it runs out of units.

Related functions

Find what still needs converting

Find every script that still calls nlapiYieldScript

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.

Add to Chrome — freeRead the migration guide

Examples are simplified. Test converted code in a NetSuite sandbox before deploying. SuiteMigrate is not affiliated with Oracle or NetSuite.