Key SuiteScript 2.x Development Concepts
Before you get started, it might help to review a few key concepts and terms that are central to SuiteScript 2.x development. Some of these terms appear in the steps later in this tutorial. You can read about these concepts now or skip ahead to Enable the Client SuiteScript Feature.
SuiteScript Versions
The sample script here uses SuiteScript 2.0. There's also a newer version, SuiteScript 2.1, which supports new language features from ES2019. You can write your scripts in either SuiteScript 2.0 or 2.1.
-
For help writing scripts in SuiteScript 2.x, see SuiteScript 2.x Entry Point Script Creation and Deployment.
-
For more info about SuiteScript versions and 2.1, see SuiteScript Versioning Guidelines and SuiteScript 2.1.
SuiteScript Reserved Words
Like most programming languages, SuiteScript has a list of reserved words you can't use as variable or function names in your scripts. For example, var is used to declare a variable, and try marks the start of a try-catch block. For more information, see SuiteScript Reserved Words.
SuiteScript 2.x Script Types and Entry Points
Before you start writing your script, you need to pick which predefined script type to use. Each script type is made for certain situations and specific triggering events. The following are some of the available SuiteScript 2.x Script Types:
-
The SuiteScript 2.x Client Script Type is for scripts that should run in the browser.
-
The SuiteScript 2.x Scheduled Script Type is for server scripts that should run at a specific time or on a recurring schedule.
-
The SuiteScript 2.x RESTlet Script Type is for server scripts that should run when called over HTTP by an application external to NetSuite.
Each script type has one or more entry points unique to that type. An entry point is where the system hands control of NetSuite to your script. When you add an entry point to your script, you're telling the system to do something when that entry point is triggered. This runs a function in your script, called an entry point function.
For many script types, entry points are like events, or the different things that can happen, to trigger your script. For example, client script entry points are events that can happen in a browser session, like fieldChanged(scriptContext) when a field value changes, or pageInit(scriptContext) when a page loads. In contrast, the scheduled script type has only one entry point, called execute. This is when a schedule runs the script or a user runs it manually.
In the example in this tutorial, you want a dialog alert to pop up when someone loads the NetSuite task record page in a browser. So, this example uses the client script type and the pageInit entry point.
SuiteScript 2.x Modules
SuiteScript 2.x uses Modular Architecture. All its APIs are organized into standard modules, and each module’s name shows what it does. For example, the N/record Module lets you work with NetSuite records, while N/https Module lets you make HTTPS requests to external web services.
Most modules need to be loaded in your script before you can use their APIs. Loading a JavaScript module is kind of like importing a library in Java—it gives you access to code that's defined somewhere else. In an entry point script, you load modules through the define Object. You list the modules you want to load as arguments.
Some APIs are globally available, so you can use them without loading their modules first. You’ll find a list of these globally available APIs in SuiteScript 2.x Global Objects.
The example in this tutorial uses both: some globally available APIs, and a method that only works after you load the right module.
Entry Point Scripts Versus Custom Module Scripts
The example script includes everything in one file. But sometimes you’ll want scripts that use logic from other files. In SuiteScript 2.x, these extra files are called custom module scripts.
The main script file—the one that sets the script type, entry point, and entry point function—is called an entry point script. Entry point scripts have their own formatting rules, which are different from custom module scripts. The next steps in this tutorial point out some of these requirements.
This topic doesn’t cover custom module scripts. For more on those, see SuiteScript 2.x Custom Modules.