Using ES6 with SuiteScript 2.0

At SuiteWorld 2017, NetSuite announced that they would be supporting ECMAScript 5, but what if you want to use the newer ECMAScript 6? Our R&D team have been using the newer ES6 with SuiteScript 2.0 for the past few months with great success, and here is how!

What is ECMAScript?

ECMAScript or ES is a scripting language specification, it is primarily used for JavaScript, but there are some other languages that follow the same specification. When we talk about ECMAScript 6 or ES6 we are pretty much saying that we are using a newer version of JavaScript.

You can view some of the features of ES6 here.

At 3EN we are big fans of arrow functions:

// Expression bodies
var odds = => v + 1);
var nums =, i) => v + i);
var pairs = => ({even: v, odd: v + 1}));

// Statement bodies
nums.forEach(v => {
  if (v % 5 === 0)

// Lexical this
var bob = {
  _name: "Bob",
  _friends: [],
  printFriends() {
    this._friends.forEach(f =>
      console.log(this._name + " knows " + f));

And Classes:

class SkinnedMesh extends THREE.Mesh {
  constructor(geometry, materials) {
    super(geometry, materials);

    this.idMatrix = SkinnedMesh.defaultMatrix();
    this.bones = [];
    this.boneMatrices = [];
  update(camera) {
  get boneCount() {
    return this.bones.length;
  set matrixType(matrixType) {
    this.idMatrix = SkinnedMesh[matrixType]();
  static defaultMatrix() {
    return new THREE.Matrix4();

You might be thinking to yourself, yeah these features are cool but do I really need them. In reality a developer doesn't need to be using these features nor do they need to adopt all these features immediately. However it's important to be aware of new language features as they could save time during implementation or testing as well as creating more readable code for the future.


How to use ES6 with NetSuite

To enable these new language features we need to use something to convert our ES6 code to ES5 code, that NetSuite can interpret. To do this we use Babel.


Initial Setup

Our NetSuite SuiteScript projects all use NPM to manage dependencies and add some useful tooling like babel.

To add babel to your project run the following command:

npm install --save-dev babel-cli

This will add the Babel command line tools to your project. To make things easier we like to run the babel compiler when we execute "npm run build" to enable this, add the following to your node package.json

"scripts": {
    "build": "babel src -d dist"

"dist" is the directory name that your code lives in.


Helper Script (Optional)

We have a small javascript file that copies all our scripts from our src directory to our dist directory. Here it is if you would like to use it in your project:

var fs = require('fs-extra');
var path = require('path');

var distSuiteScriptPath = path.join(__dirname, '..', 'dist');

if (fs.existsSync(distSuiteScriptPath)) {

You will need to run the following command to bring in the dependencies for this script:

npm install --save-dev fs-extra

And update your package.json to execute the script:

"scripts": {
    "build": "node ./npm_scripts/build.js; babel src -d dist"


Configuring a .babelrc file

To configure babel we need to setup a .babelrc file in the root of our project. This informs babel on what compiler to use. In this example we are going to use the present-env plugin, which enables transforms for ES2015+

Create a .babelrc file with the following contents:

  "presets": ["env"]

And run the following command to bring in the present-env dependency

npm install babel-preset-env --save-dev

Test it out

You will now be able to use ES6 + SuiteScript 2.0, here's an example module that loads an employee record for you to get started

define(['N/record'], function(record) {

  //Employee Class Definition - ES6 😎
  class Employee {
    constructor(employeeRecord) {
      if(employeeRecord) {
        this.internalId =;
        this.firstName = employeeRecord.getValue('firstname');
        this.lastName = employeeRecord.getValue('lastname'); = employeeRecord.getValue('email');

  function get(internalId) {

    const employeeRecord = record.load({
      "type": record.Type.EMPLOYEE,
    const employee = new Employee(employeeRecord);
    return employee;

  return {


To stay in the loop for further news, guides, resources and more, sign up to "insight" our flagship weekly NetSuite and Business Software Newsletter, click here.