Skip to content

zsf3/typings-suitescript-2.0

 
 

Repository files navigation

SuiteScript 2.0 Typings

Join the chat at https://gitter.im/typings-suitescript-2-0/Lobby

Installation Instructions

npm install --save-dev @hitc/netsuite-types

Usage

Once installed, you need to configure TypeScript to find the library declarations and import the libraries as needed into your scripts.

TSC (TypeScript Compiler) Configuration

You can import the modules and use them like normal using standard TypeScript syntax. Just make sure your compiler is configured to use the amd module format and the es5 target. Create a file called tsconfig.json in your project root and have these options configured:

{
  "compilerOptions": {
    "module": "amd",
    "target": "es5",
    "moduleResolution":"node",
    "sourceMap": false,
    "newLine": "LF",
    "experimentalDecorators": true,
    "noImplicitUseStrict": true,
    "baseUrl": ".",
    "lib": ["es5", "es2015.promise", "dom"],
    "paths": {
      "N": ["node_modules/@hitc/netsuite-types/N"],
      "N/*": ["node_modules/@hitc/netsuite-types/N/*"]
    }
  },
  "exclude": ["node_modules"]
}

The key components are baseUrl and paths.

Then simply import your modules and go.

Writing SuiteScript

At the top of every script you will want to have the following lines added:

/**
 * @NAPIVersion 2.0
 * @NScriptType ClientScript
 */

import {EntryPoints} from 'N/types';

EntryPoints isn't actually in the NetSuite API, but it is something that is included with this library to give you type definitons for your entry point functions. For example:

import {EntryPoints} from 'N/types';
export var pageInit: EntryPoints.Client.pageInit = (ctx) => {
  //Your IDE will now autocomplete from the ctx argument. For instance use this to access ctx.mode and ctx.currentRecord in this pageInit example
}

A full example might look something like this:

/**
 * @NAPIVersion 2.0
 * @NScriptType UserEventScript
 */

import {EntryPoints} from 'N/types'
import * as log from 'N/log'

export function beforeSubmit(ctx: EntryPoints.UserEvent.beforeSubmitContext) {

    let x = ctx.newRecord.getValue({fieldId: 'companyname'})

    log.audit('value', `companyname is: ${x}`)

}

Then if you're using a TypeScript-aware text editor (for instance the free VSCode from Microsoft) you'll get syntax highlighting, error detection, and autocomplete for all of the SuiteScript 2.0 modules and types.

Updates

You can download the latest published typings library at any time by simply running the command:

npm install --save-dev @hitc/netsuite-types

About

TypeScript typings for SuiteScript version 2.0

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 99.1%
  • TypeScript 0.9%