SuiteScript 2.1 Anatomy of a Script

SuiteScript 2.1 entry point scripts follow the same basic structure, as shown in the diagram. Check out the table after the diagram for an explanation of each part. For a walkthrough of the script creation steps, see SuiteScript 2.1 Script Creation Process, and for step-by-step instructions to create a sample script, see SuiteScript 2.1 Hello World.

For background on the concepts used in this topic, see SuiteScript 2.1 Development Concepts. For information about script version values, see SuiteScript Versioning Guidelines.

Anatomy of basic SuiteScript 2.1 user event script.

General Area

Callout

Description

0 - JSDoc tags

2 and 3

The @NApiVersion tag is required in an entry point script, and its value can be 2.0, 2.1, 2.x, or 2.X.

4 and 5

The @NScriptType tag is also required. The value isn't case sensitive, but using Pascal case, like in this example, makes it easier to read.

1 - define statement

6

The first argument of the define function is a list of dependencies, or modules, that the script loads. In this script, the dependencies are the N/record module for records and the N/ui/serverWidget module for forms.

7

The second argument for the define function is a callback function.

8

The callback function's arguments represent the modules you listed as dependencies. The first argument is for the N/record Module, and the second is for N/ui/serverWidget Module. The order of these arguments matches the order of the modules in the define function dependency list. (Callout 6)

You can use these objects anywhere in the callback function to access the module APIs. You can name them whatever you like, but it's best to use names similar to the module names.

9, 10, and 11

These are the entry point functions. To use a function, you need to name it in the return statement next to an entry point, like in Callout 17.

12, 13, and 14

This is the context object that's provided to each entry point function. What's included in this object depends on the entry point you're using. For more details, see Context Objects in Entry Point and Custom Module Scripts.

15

The callback function's return statement.

16

The entry points used. The script needs to use at least one entry point, and any entry points you use must match the script type set by the @NScriptType tag (see Callouts 4 and 5).

17

References to the script's entry point functions. For each entry point, your script needs to point to an entry point function you've defined elsewhere in the script.

Related Topics

General Notices