SuiteScript 2.x Advantages

SuiteScript 2.x is a complete redesign of the SuiteScript model from 1.0. This topic covers some of the advantages SuiteScript 2.x has over 1.0.

Note:

Use SuiteScript 2.x for any new scripts you create, and think about converting your SuiteScript 1.0 scripts to SuiteScript 2.0 or 2.1. SuiteScript 1.0 isn’t being updated anymore, and there are no new features or enhancements for it. While SuiteScript 1.0 scripts are still supported, you should use SuiteScript 2.0 or 2.1 for any new or majorly updated scripts to take advantage of new features, APIs, and functionality improvements.

Complexity Management and Intuitive Code Organization

SuiteScript 2.x is built around modularity. Modern SuiteApps need complex scripts with lots of code and files, and modularity helps manage that complexity. It also adds encapsulation, makes code organization more intuitive, and prevents global variable or method naming conflicts.

SuiteScript 2.x comes with a full set of new APIs, all organized into modules based on what they do. For example, you use the N/file module to work with files in NetSuite. Your script only loads the modules it needs. In SuiteScript 1.0, all APIs are in one big global namespace, so every script uses the whole namespace no matter which APIs it needs.

SuiteScript 2.x also lets you create your own custom modules. You can use these to organize your code (instead of SuiteScript 1.0 libraries). You can even add custom modules to SuiteApps and share them with third parties.

For additional information, see the following help topics:

Note:

SuiteScript 2.x uses the Asynchronous Module Definition (AMD) specification to define and load JavaScript modules and their dependencies. For more about AMD, see http://requirejs.org/docs/whyamd.html and https://github.com/amdjs/amdjs-api/blob/master/AMD.md.

Automatic Dependency Management

SuiteScript 2.x gives you built-in dependency management. You define which modules need to load before your script runs, and the module loader takes care of loading those modules and all their dependencies automatically. This means you can focus on your logic instead of worrying about dependencies and load order.

For additional information, see the following help topics:

Modern Programming Syntax and Behavior

SuiteScript 2.x is designed to be similar to JavaScript, so it’s easier for JavaScript developers to pick up. The syntax is straightforward and the behavior is consistent. Some of the enhancements include:

  • Third party JavaScript API support: SuiteScript 2.x supports all standard JavaScript. The SuiteScript 2.x APIs let you access NetSuite features programmatically. For generic logic, you can use custom modules to load your favorite third-party JavaScript APIs.

  • SuiteScript 1.0 nlapi/nlobj prefix retirement: SuiteScript 2.x is designed to look and work like modern JavaScript, so its methods and objects don’t use the nlapi or nlobj prefixes anymore. This change fits with the modular structure of SuiteScript 2.x—methods and objects are now inside modules, while SuiteScript 1.0 kept everything in the nlapi and nlobj namespaces.

  • Usage of properties and enumerations: SuiteScript 2.x uses properties and enumerations. Most getter and setter methods from SuiteScript 1.0 are now properties, and enumerations are used for common constants like standard record types.

    Note:

    JavaScript doesn’t have a built-in enumeration type. In SuiteScript 2.x, an “enumeration” (or enum) is a plain JavaScript object with a flat, map-like structure, where each key points to a read-only string value.

  • Updated sublist and column indexing: Most programming languages start indexing at 0, but SuiteScript 1.0 started sublist and column indexing at 1. SuiteScript 2.x now starts indexing at 0 to match modern JavaScript.

  • There’s also a new version, SuiteScript 2.1, which is the latest minor version. It adds support for more ECMAScript features and syntax. For more info, see SuiteScript 2.1.

For additional information, see the following help topics:

Functionality Enhancements

The following enhancements are exclusive to SuiteScript 2.x:

Map/Reduce Script Type

SuiteScript 2.x introduces a new server script type based on the map/reduce model. Map/reduce scripts give you a structured way to process lots of records on the server. If you’re a SuiteCloud Plus user, you can even process records in parallel across multiple processors, and you get to choose how many processors to use right from the script deployment record.

For additional information, see SuiteScript 2.x Map/Reduce Script Type.

Asynchronous Processing (Promises)

Promises are JavaScript objects that represent the result of an asynchronous process. Once you create a promise, it acts as a placeholder for whether an operation will succeed or fail. While a promise is waiting in the background, the rest of your script can keep running.

In SuiteScript 2.x, all client scripts and some server scripts support promises. With promises, you can write asynchronous code that’s both intuitive and efficient. SuiteScript 2.x includes promise APIs for certain modules, and you can also create custom promises in any client script.

For additional information see Promise Object.

SFTP File Transfer API

SuiteScript 2.x supports SFTP (Secure File Transfer Protocol), so you can securely transfer files between NetSuite and external FTP servers. SFTP is packaged with SSH and works like FTP, but with a secure connection. To authorize the server, you’ll need a password GUID (Globally Unique Identifier) and either of the following:

  • DSA (Digital Signature Algorithm

  • ECDSA (Elliptical Curve Digital Signature Algorithm)

  • RSA (cryptosystem) host key

For additional information, see N/sftp Module.

Cache API

The SuiteScript 2.x Cache API lets you load data into a cache and share it with one or more scripts. This feature helps cut down the time it takes to retrieve data.

For additional information, see N/cache Module.

Search Pagination API

The SuiteScript 2.x Search Pagination API lets you page through search results. This makes scripts run faster and gives you an easy way to work with large sets of search data.

For additional information, see N/search Module.

Flat File Streaming API

With SuiteScript 1.0, you can’t easily access files larger than 10MB. You’d have to split big files into smaller ones to read, write, or append their contents in memory.

The SuiteScript 2.x Flat File Streaming API lets you efficiently process and stream large CSV and plain text files. You can load and edit each line in memory, then put the lines back together. The 10MB limit now only applies to individual lines, not the whole file.

For additional information, see N/file Module.

Expanded Support for HTTP Content Type Headers

SuiteScript 2.x supports all HTTP content types, for both client requests and server response headers.

For additional information, see N/http Module and N/https Module.

New Encryption/Encoding Functionality

SuiteScript 2.x adds better encryption, decryption, and hashing with the N/crypto Module, plus extra encoding features in the N/encode Module.

Related Topics

General Notices