SuiteScript 2.x Anatomy of a Custom Module Script

All SuiteScript 2.x custom module scripts must conform to the same basic structure. The following diagram illustrates that structure. For an explanation of the numbered components of the script, refer to the table that follows the diagram.

Structure of a custom module script.

General Area

Callout

Description

0 — JSDoc tags and other annotations

2

The title of the file that holds this script. This annotation is not required, but it can be useful. Any script that loads this module must refer to this name.

3 and 4

The @NApiVersion tag and its value. This tag is not required in a custom module script, but you may want to include it to prevent compatibility problems with scripts that use future versions of SuiteScript.

5 and 6

The @NModuleScope tag and its value. This tag is optional. You can use it to limit the access that other scripts have to this module. For more information about this tag, see Controlling Access to Scripts and Custom Modules.

1 — define function

7

The define function’s first argument, which is a list of modules required by the script. This script uses only one: the N/record Module, which lets the script interact with records.

8

The define function’s second argument, which is a callback function.

9

The arguments of the callback function. Because this script loads only one module, the callback function takes only one argument. This argument represents the N/record Module and can be used anywhere in the callback function to access the module’s APIs. You can give this object any name you prefer but, as a best practice, use a name that is similar to the module name.

10

The script’s entry point function. As you can see in the return statement (Callout 12), this entry point function is associated with the entry point named schedule.

11

The context object that is made available when the schedule entry point is invoked. The values of this object’s properties are defined in the script that calls this custom module. For an example, see SuiteScript 2.x Custom Module Tutorial.

12

The callback function’s return statement.

13

The custom module’s entry point. As with an entry point script, every custom module script must use at least one entry point. The difference is that an entry point script must use a standard entry point that is part of the script type identified by the @NScriptType JSDoc tag. A custom module entry point is your creation, so you can use this return statement to give the entry point any name you prefer.

14

The entry point function returned when the schedule entry point is invoked. For each entry point used, your custom module script must identify some object, usually a function, that is returned.

Note:

For details on the standard structure for an entry point script, see SuiteScript 2.x Anatomy of a Script.

Related Topics

General Notices