SuiteScript 2.x Custom Modules

With SuiteScript 2.x, you have the ability to create custom modules (including third-party, AMD, and non-AMD modules). This supports modular and well-structured organization of code that is easier to read and modify. It also lets you build and access additional, customized API functionality.

Build a custom module to:

Note:

Custom modules are not supported in bundle installation scripts.

To learn about how a custom module is structured, see SuiteScript 2.x Anatomy of a Custom Module Script. You can also learn how to create and use a custom module by following the SuiteScript 2.x Custom Module Tutorial.

As you create your custom module, you may find the following topics useful:

Custom Module Prerequisites

Before you create and use a custom module, make sure you’re familiar with the following topics:

Creating a Custom Module

To create your custom module, you must use the define Object. You will always use the define Object when creating custom modules and entry point scripts. You should also use the define Object when referencing a script file in the File Cabinet using a relative path.

Every custom module script must define an object that is returned when the script’s entry point is invoked. This object could be a static value, such as a string. However, it is more common for custom module scripts to return a function. As with an entry point function in a standard entry point script, this function takes a context object as its argument.

You can include standard and custom JSDoc tags in your custom module scripts. You should use the @NApiVersion and @NModuleScope tags to indicate the API version of the script and the module scope. For custom modules that are not entry point scripts, the @NApiVersion tag specifies the SuiteScript version your module uses. The @NApiVersion tag also prevents compatibility issues if a script that references this custom module uses another SuiteScript version with language features or syntax that your custom module does not support. The @NModuleScope tag determines whether other scripts and accounts can access your custom module. For more information about controlling access of the custom module, see Controlling Access to Scripts and Custom Modules.

For general information about JSDoc tags, see SuiteScript 2.x JSDoc Validation.

You can use JSDoc and custom JSDoc tags to create your own documentation for scripts, custom modules, and SuiteApps. To take advantage of this tool, you must download JSDoc from the official website. For additional information about JSDoc, see https://jsdoc.app/.

For examples of custom module scripts, see Custom Module Examples.

Using Your Custom Module

To use your custom module, it must be referenced by another script that has been deployed. You must create a separate entry point script to reference and trigger your custom module. You can load and specify the name of your custom module using an absolute path, with the require Function. For more information about how to use absolute and relative paths, see Module Dependency Paths.

After you create your custom module and reference script, you need to upload them to your File Cabinet in NetSuite (Documents > Files > File Cabinet > SuiteScripts). For entry point scripts that reference your custom module, you must create a script record and deployment record. For more information about creating a script record, see SuiteScript 2.x Entry Point Script Creation and Deployment.

To learn about using a custom module name, see Naming a Custom Module.

Related Topics

General Notices