SuiteScript 2.x Advantages

SuiteScript 2.x is a complete redesign of the SuiteScript model used in SuiteScript 1.0. This topic discusses several of the advantages SuiteScript 2.x has over SuiteScript 1.0.

Note:

Use SuiteScript 2.x for new scripts that you develop, and consider converting your SuiteScript 1.0 scripts to SuiteScript 2.0 or SuiteScript 2.1. SuiteScript 1.0 is no longer being updated, and no new feature development or enhancement work is being done for this version. SuiteScript 1.0 scripts continue to be supported, but you should use SuiteScript 2.0 or SuiteScript 2.1 for any new or substantially revised scripts to take advantage of new features, APIs, and functionality enhancements.

Complexity Management and Intuitive Code Organization

SuiteScript 2.x is built on modularity. Modern SuiteApps require complex scripts that typically consist of many lines of code and many files. Modularity gives users built-in complexity management. It also adds encapsulation, provides intuitive code organization, and ensures there are no global variable or method naming conflicts.

SuiteScript 2.x comes with a complete set of new APIs, contained within modules. These modules are organized and named based on behavior. For example, you use the N/file module when you need to work with files in NetSuite. Your script loads only those modules that it needs. With SuiteScript 1.0, all APIs are contained in the same global namespace. Each SuiteScript 1.0 script utilizes the entire namespace, regardless of which APIs it uses.

SuiteScript 2.x also enables you to create your own custom modules. You can use these custom modules to organize your code (as a replacement for SuiteScript 1.0 libraries). Additionally, you can add custom modules to SuiteApps and expose those modules to third parties.

For additional information, see the following help topics:

Note:

SuiteScript 2.x implements the Asynchronous Module Definition (AMD) specification. AMD is used to define and load JavaScript modules and their dependencies. For additional information regarding 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. With SuiteScript 2.x, you define the SuiteScript 2.x modules and custom modules that must load prior to script execution. The module loader automatically loads the dependencies of those modules, the dependencies of the dependencies, and so forth. Automatic dependency management enables you to concentrate on logic instead of dependencies and load order.

For additional information, see the following help topics:

Modern Programming Syntax and Behavior

The underlying principle of SuiteScript 2.x is that it is similar to JavaScript. This results in a decreased learning curve for experienced JavaScript developers. The syntax is straightforward JavaScript and the behavior is consistent. Enhancements to syntax and behavior include the following:

  • Third party JavaScript API support: SuiteScript 2.x is designed to support all standard JavaScript. The supplied SuiteScript 2.x APIs give you programmatic access to NetSuite functionality. For generic logic, use custom modules to load your preferred third party JavaScript APIs.

  • SuiteScript 1.0 nlapi/nlobj prefix retirement: SuiteScript 2.x is modeled to look and behave like modern JavaScript. To meet that objective, SuiteScript 2.x methods and objects are not prefixed with nlapi and nlobj. This change also reflects the modular organization of SuiteScript 2.x. SuiteScript 1.0 methods and objects belong to the nlapi and nlobj namespaces, respectively. SuiteScript 2.x methods and objects are encapsulated within various modules.

  • Usage of properties and enumerations: SuiteScript 2.x adopts the usage of properties and enumerations. Most SuiteScript 1.0 getter and setter methods are replaced with properties in SuiteScript 2.x, and enumerations encapsulate common constants (for example, standard record types).

    Note:

    JavaScript does not include an enumeration type. The SuiteScript 2.x documentation uses the term enumeration (or enum) to describe the following: a plain JavaScript object with a flat, map-like structure. Within this object, each key points to a read-only string value.

  • Updated sublist and column indexing: The standard practice in the development world is to start indexing at 0. This behavior is observed in the majority of programming languages. SuiteScript 1.0 starts sublist and column indexing at 1. To bring SuiteScript into alignment with modern JavaScript, sublist and column indexing within SuiteScript 2.x begins at 0.

  • A new version of SuiteScript, SuiteScript 2.1, is also available. This version is the latest minor version of SuiteScript. It extends SuiteScript 2.x by supporting additional ECMAScript language features and syntax. For more information, 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 provide a structured framework for server scripts that process a large number of records. In addition, SuiteCloud Plus users can also use map/reduce scripts to process records in parallel across multiple processors. Users manually select the number of processors to use 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 eventual result of an asynchronous process. After these objects are created, they serve as placeholders for the future success or failure of an operation. During the period of time that a Promise object is waiting in the background, the remaining segments of the script can execute.

In SuiteScript 2.x, all client scripts, and a subset of server scripts, support the use of promises. With promises, developers can write asynchronous code that is intuitive and efficient. SuiteScript 2.x provides promise APIs for selected modules. In addition, you can create custom promises in all client scripts.

For additional information see Promise Object.

SFTP File Transfer API

SuiteScript 2.x provides support for SFTP (Secure File Transfer Protocol). This feature enables you to securely transfer files between NetSuite and external FTP (File Transfer Protocol) servers. SFTP is a protocol packaged with SSH (Secure Shell). It is similar to FTP, but files are transferred over a secure connection. Server authorization requires a password GUID (Globally Unique Identifier) and a DSA (Digital Signature Algorithm), ECDSA (Elliptical Curve Digital Signature Algorithm), or RSA (cryptosystem) host key.

For additional information, see N/sftp Module.

Cache API

The SuiteScript 2.x Cache API enables you to load data into a cache and make it available to one or more scripts. This feature reduces the amount of time required to retrieve data.

For additional information, see N/cache Module.

Search Pagination API

The SuiteScript 2.x Search Pagination API enables you to page through search results. This enhancement increases script performance and gives you an intuitive means to efficiently traverse search result data.

For additional information, see N/search Module.

Flat File Streaming API

With SuiteScript 1.0, you cannot easily access the contents of files that are over 10MB. You must partition your files into smaller, separate files to read, write, and append file contents in memory.

The SuiteScript 2.x Flat File Streaming API enables you to efficiently process and stream large CSV and plain text files. With this enhancement, you can load and edit each line of content into memory, and then append the lines back together. The Flat File Streaming API enforces the 10MB limit only on individual lines of content.

For additional information, see N/file Module.

Expanded Support for HTTP Content Type Headers

SuiteScript 2.x adds support for all HTTP content types. This enhancement applies to both client request and server response HTTP headers.

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

New Encryption/Encoding Functionality

SuiteScript 2.x adds enhanced encryption, decryption, and hashing functionality with the N/crypto Module. Additional encoding functionality is exposed in the N/encode Module.

Related Topics

General Notices