Displaying items by tag: suitescript 21

Thursday, 07 November 2019 16:35

Alta Via digging deep into #SuiteScript

A major step in moving SuiteScript to the 21st Century.

As NetSuite recently published SuiteScript 2.1  we were curious and took a deeper look into it. ... Pssst! we can use #ECMAscript 6 now :)
I was very excited when I heard it is coming and finally we have the freedom of using all the newest JavaScript features, so let's try to use it. 

Why would you want to use it?

 If you wanted to use the latest  version of ECMAScript without being forced to transform your code, so that NetSuite would understand it, by e.g. using babel or some other transpiling tool - the solution has just arrived. The new SuiteScript 2.1 (for the time being still in Beta).

The script header:

 My first script with 2.1 started with a question: which value for @version tag should be used. I started with 2.x which in theory should always match the latest version of SuiteScript. Unfortunately this option does not work yet. For the time being 2.x equals 2.0 and if you try to use it 2.x and some of the newest features of javascript you will get syntax errors, so my final header looked like this:

 *  @NApiVersion 2.1
 *  @NScriptType UserEventScript

Next step was to find a way to add a library script. In 2.0 I used to use:

* @NAmdConfig /SuiteScripts/configuration.json

where configuration.json was a file that contained mapping  

  "paths": {
    "myLib": "/SuiteScripts/Libraries/myCustomLib",


Thanks to that I was able to use myLib as a reference to myCustomLib.js in define clause like this:

    function (myLib) {

However, it does not work in 2.1. I thought that maybe you need to use javascript modules instead (@export/@import), but when you try to use them the script is throwing syntax errors. It seems like some defect, or lacking feature in Beta, but the only way for now to add external libraries is to actually use a url in the define clause like:

   function (myLib) {

Use Classes:

 After workarounding the problems above, I was able to create a fully operational user event script with libraries attached. Moreover it seems that all the latet ECMAScript features are working (Hurray!) - I could use classes:

  class ShippingInformation {

   * @param {*} itf
   * @param {*} itemsData

   constructor(itf, itemsData) {
       this.boxes = [];
       this.itemsData = itemsData;
       this.itf = itf;

Variables: Const and let

Block scope variables and constants :

for (let i = 0; i < count; i++) {

    let item = this.itf.getSublistValue({
    sublistId: 'item',
    fieldId: 'item',
    line: i

const itemData = this.itemsData[item];

Lambda functions:

  * @returns {Array}

  hasEmptySpace() {

    const uniqueItems = this.lines.map((line) => line.item).filter((x, i, a) => a.indexOf(x) === i);

    return uniqueItems.length < 3 && this.spaceUsed < 1;


As of now my script works in my customer’s production account without any issues, so i believe 2.1 is stable.

Let's hope that NetSuite will shortly stop to consider SuiteScript 2.1 as a Beta feature and also add support for it in debugger.

 All in all, finally some major step in moving SuiteScript to 21st Century!

Published in Script Solution


O NetSuite SuiteCloudDeveloperNetwork rgb 2NetSuite SolutionProvider horiz rgb

NOTE! This site uses cookies and similar technologies.

If you not change browser settings, you agree to it.

I understand