SuiteScript 2.x Anatomy of a Script

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

Note:

If you need help with any of the terms in this topic, SuiteScript 2.x Hello World.

Anatomy of basic SuiteScript 2.x 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.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 for the define function is a list of dependencies, or modules the script loads. In this script, it uses the to work with records and the to work with 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 matches the order in the define function’s 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 for Standard and Custom Entry Points.

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