Getting Started with SuiteScript 2.1, TypeScript, and the SuiteCloud Development Framework (SDF)

By leveraging the latest SuiteCloud Platform technologies, SuiteScript 2.1 and SDF with a strongly typed, object-oriented language like TypeScript, you can streamline building account customizations faster. Whether you’re a beginner starting from scratch or seeking to enhance your existing customizations, you will find this useful. The specific advantages of each technology will be explained, and you will learn how to set up an SDF project to fully capitalize on SuiteScript 2.1, TypeScript, and ECMAScript.

  • Disclaimer: The NetSuite team does not officially support TypeScript or any third party libraries mentioned in this guide. TypeScript is used as a dev-dependency that’s transpiled in your local environment and not in the NetSuite ecosystem.

Each of these technologies offers significant benefits:

  • SDF provides a structured and efficient approach to managing the software development lifecycle, enabling seamless collaboration and version control.
  • SuiteScript 2.1 is the latest product version that empowers NetSuite developers with advanced functionality to create customizations on the SuiteCloud Platform.
  • TypeScript enhances code quality and maintainability with static typing and advanced error checking, leading to fewer runtime errors and improved developer productivity.
  • ECMAScript delivers modern JavaScript features in SuiteScript 2.1, such as import statements, arrow functions, and template literals, contributing to cleaner, more modular code and building future-proof applications as JavaScript continues to evolve.
  • Note: SuiteScript 2.1, TypeScript, and JavaScript support `let` and `const` keywords for declaring variables, arrow functions, template literals, and more.

Setting Up Your SDF Development Environment

Before you dive in, ensure you have set up SDF correctly. We will use SDF to define your project and sync local files with your NetSuite account. If you already have your account and development environment set up, you can skip this step.

The following setup will enable your NetSuite account with the required roles and permissions, set up an Integrated Development Environment (IDE) based on Visual Studio Code, and install all necessary SDF CLI tools. Finally, you will have to link an account to your SuiteCloud Projects.

You can watch this three part video to get your account setup:

If you encounter any issues enabling features, consider seeking help from an administrator – additional details are provided below.

●      Enabling SuiteCloud Development Framework in the Target NetSuite Account (Administrator Only)

●      Assigning the Developer Role (Administrator Only)

●      SuiteCloud Development Framework Account Preferences (SDF Developers Only)

●      Setting Up a Role for SuiteCloud Development Framework Development

Create Account Customization Project

To get started, create a new SDF project using the SuiteCloud Extension for Visual Studio Code. This project will act as a container for all the customizations you’ll be working on.

To create a new project using the SuiteCloud Extension for VS Code, follow these steps:

  1. Install Visual Studio Code: Download and install Visual Studio Code
  2. Install SuiteCloud Extension for VS Code: In VS Code, go to the Extensions, search for “SuiteCloud Development Framework” and click “Install”.
  3. Set Up NetSuite Account Credentials: Click on the gear icon in the bottom-left corner of the VS Code window to open the extension settings. Look for the “SuiteCloud” section, and enter your NetSuite account credentials in the appropriate fields.
  4. Create a New Project: Click on the Explorer icon in the Activity Bar to open the File Explorer. Right-click on the folder where you want to create your new project and select “New SuiteCloud Project.”
  5. Enter Project Details: In the input box that appears, provide the necessary details for your new project, such as the project name, ID, and description. Press Enter when you’re done, and the extension will create the project structure for you.

Your new SuiteCloud project is now set up in the selected folder. You can start developing customizations by creating new SuiteScripts, Suitelets, or other NetSuite components inside the File Cabinet folder.

Here are some very useful SDF commands:

The SuiteCloud extension provides various commands accessible from the Command Palette (Ctrl + Shift + P). You can use these commands to deploy your project, create new script files, and more. Using these commands, you can effectively manage and develop your SuiteCloud projects within Visual Studio Code, making the development process more efficient and accessible.

  • “SuiteCloud: Deploy Project”: Deploys all project files including configurations, objects, and scripts from your local project to your NetSuite account.
  •  “SuiteCloud: Update Object from Account”: Creates SDF custom objects (XML) from your NetSuite account to your local project.
  • “SuiteCloud: Upload File”: This command allows you to upload the opened file in your IDE.

Alternatively, you can right click on a folder or file and you’ll see these options. For more useful tips and examples, refer to this helpful reference: https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/chapter_158400948906.html

Project Setup with TypeScript

By leveraging the VS Code SuiteCloud IDE Plug-In, you’ve seamlessly set up your account customization project with connectivity to NetSuite services. With most of the work already done, the final step involves installing TypeScript into your project. This integration ensures that your SuiteScript 2.1 customizations become more reliable and efficient, while maximizing the benefits of the SuiteCloud IDE Plug-In for a streamlined development experience.

First, create a package.json file in the root directory:

{

    “name”: “SDF TypeScript Project”,

    “version”: “1.0.0”,

    “devDependencies”: {

        “@hitc/netsuite-types”: “^2023.1.9”,

        “typescript”: “^5.0.4”

    }

}

Next, run npm install in the root directory. 

Note: Typescript and netsuite-types packages are devDependencies, which you install on your local machine for tasks like formatting, testing, and building. These packages are not included in the production build of your application. The netsuite-types package provides TypeScript type definitions and declarations for the NetSuite SuiteScript API, allowing you to write type-safe code and benefit from code completion and type checking while working with NetSuite SuiteScript in your TypeScript projects.

Next, create a tsconfig.json file in the root directory:

{

    “compilerOptions”: {

      “module”: “amd”,

      “target”: “ESNext”,

      “sourceMap”: false,

      “esModuleInterop”: true,

      “experimentalDecorators”: true,

      “noUnusedLocals”: false,

      “moduleResolution”: “node”,

      “newLine”: “LF”,

      “baseUrl”: “.”,

      “lib”: [“ESNext”, “dom”],

      “paths”: {

        “N”: [“node_modules/@hitc/netsuite-types/N”],

        “N/*”: [“node_modules/@hitc/netsuite-types/N/*”]

      },

      “outDir”: “src/FileCabinet/SuiteScripts/”

    },

    “include”: [“src/TypeScripts/*”],

    “exclude”: [“node_modules”]

}

Finally, create a folder under the src folder called TypeScripts  where you will place the TypeScript files. Once you write your SuiteScript 2.1 code and save it in the TypeScript folder, running the tsc command in the terminal will invoke the TypeScript compiler. The compiler will look for the tsconfig.json file, transpile the TypeScript code into JavaScript, and save it to a file inside the SuiteScripts folder in FileCabinet.

Your project structure should look like this:

By taking full advantage of the capabilities available with SuiteScript 2.1, SDF, and TypeScript in your NetSuite customization projects, you can achieve faster iterations, develop higher-quality code, and build future-resilient applications. Unlock the complete spectrum of possibilities in SuiteCloud to create robust and flexible customizations that will elevate and grow your business on NetSuite.

Leave a comment

Your email address will not be published. Required fields are marked *