SuiteScript 2.1 Custom Modules

SuiteScript 2.1 custom modules let you create and use custom logic in separate files. This approach helps you keep code modular, easier to maintain, and easier to reuse across scripts.

You can use custom modules to group reusable functions in a common library file, add shared functionality to SuiteApps, and import supported third-party libraries. You can also use them to separate utilities from business logic.

The following sections explain the core concepts and tasks involved in creating and using custom modules:

To understand how a custom module is structured, see Custom Module Script Anatomy. For a step-by-step example, see Custom Module Tutorial.

For implementation details, see Custom Module Dependency Paths, Naming a Custom Module, and Custom Module Examples.

For support information, see Common Custom Module Errors and Custom Module Guidelines.

Note:

Custom modules aren't supported in bundle installation scripts.

Custom Module Prerequisites

Before you create or use a custom module, get familiar with these topics:

Creating a Custom Module

To create your custom module, you'll need to use the define Object. Use define to create custom modules and entry point scripts. To load a module by relative path with require, include require as a dependency of define so the script has a module context.

Every custom module script has to return an object when its entry point runs. This returned object could be something simple, like a string-but usually it's a function. As with regular entry point scripts, this function gets a context object as its argument.

You can add standard and custom JSDoc tags to your module scripts. Use @NApiVersion and @NModuleScope to specify the SuiteScript version and module scope. For a non-entry module, @NApiVersion identifies the version the module uses. If a SuiteScript 2.0 entry point script references a SuiteScript 2.1 custom module, compatibility issues can occur. These issues occur when the module uses language features or syntax that SuiteScript 2.0 doesn't support. @NModuleScope controls whether other scripts and accounts can access your module. To learn more, see SuiteScript Module Scope and Access Control.

For info on JSDoc tags, see SuiteScript 2.1 JSDoc Validation.

You can use JSDoc (and your own tags) to make docs for scripts, custom modules, and SuiteApps. Read more on JSDoc from the official site: https://jsdoc.app/.

For examples, see Custom Module Examples.

Using Your Custom Module

To use your custom module, you'll need another script to reference it. Make a separate entry point script to load and trigger your custom module (using an absolute path with the require Function). For more on paths, see Custom Module Dependency Paths.

After you've made your custom module and reference script, upload them to your NetSuite File Cabinet (Documents > Files > File Cabinet > SuiteScripts). For any entry point script referencing your module, create a script record and deployment record. See SuiteScript 2.x Entry Point Script Creation and Deployment for more.

To learn how module naming works, see Naming a Custom Module.

Related Topics

General Notices