SuiteScript 1.0 and SuiteScript 2.1 API and Language Differences
SuiteScript 2.1 replaces many SuiteScript 1.0 APIs with modules and uses JavaScript conventions that can affect converted scripts. Review these differences when updating API calls, arguments, and record operations.
This topic covers the following sections:
Reserved Words
SuiteScript is based on ECMAScript, so you can't use ECMAScript reserved words as variable names, labels, or function names. Doing so can cause a syntax error when your script runs.
Suitelets also have reserved parameter names. For more information, see Reserved Parameter Names in Suitelet URLs.
In SuiteScript 2.1, log Object and util Object are reserved global object names. If SuiteScript 1.0 and SuiteScript 2.1 scripts run on the same record, a SuiteScript 1.0 variable named log or util causes an error. Update affected SuiteScript 1.0 scripts.
For more information about SuiteScript reserved words, see SuiteScript Reserved Words.
Enumerated Values
JavaScript doesn't include an enumeration type. In SuiteScript 2.1 documentation, we use the term enumeration (or enum) to describe a plain JavaScript object whose keys map to read-only string values.
Enumeration members typically take the form of constants with associated values. For example, the runtime.Permission enum in the N/runtime Module lists the FULL, EDIT, CREATE, VIEW, and NONE permission values. Another example is error.Type in the N/error Module, which lists errors that can occur when a script runs.
Enumeration values can be static or dynamic. Static values are available to all SuiteScript 2.1 scripts. Dynamic values depend on the account type and enabled features, so they may not be available in every account.
Modules
SuiteScript 2.1 organizes APIs into modules rather than the functions and objects used in SuiteScript 1.0. Module names reflect their functionality. For example, the N/record Module lets you work with NetSuite records, and the N/https Module lets you make HTTPS requests to external web services.
Most modules must be loaded before a script can use their methods, properties, or enums. To load a module, specify it as a dependency of the define function. Some APIs are globally available, so you can use them without loading their modules first.
For more information, see the following topics:
Arguments and Parameters
Arguments and parameters differ between SuiteScript 1.0 and SuiteScript 2.1. When you update a script, consider the following differences:
-
Standard SuiteScript 2.1 methods accept a single options object whose properties provide the parameters. SuiteScript 1.0 API methods accept individual arguments.
-
Parameter names can differ between equivalent SuiteScript 1.0 and SuiteScript 2.1 API methods.
-
Some SuiteScript 1.0 arguments are properties of SuiteScript 2.1 options objects.
-
Some SuiteScript 2.1 module methods accept parameters that their SuiteScript 1.0 counterparts do not.
The SuiteScript 1.0 to SuiteScript 2.1 API Map links each SuiteScript 1.0 API to its corresponding SuiteScript 2.1 module, method, or property. Use the map to compare arguments and parameters between similar APIs. It also identifies SuiteScript 1.0 functions that are now module properties in SuiteScript 2.1.
Scripting Subrecords
Subrecord handling differs significantly between SuiteScript 1.0 and SuiteScript 2.1:
-
You can use a single method to create or load a subrecord.
-
You don't save subrecords explicitly; NetSuite saves them with the parent record.
-
You must use subrecord methods to work with address subrecords. Addresses are subrecords rather than individual record fields.
For more information, see SuiteScript 2.1 Scripting with Subrecords.