SuiteScript 2.x Custom Modules
With SuiteScript 2.x, you can create custom modules—including third-party, AMD, and non-AMD modules. This keeps your code modular and easy to read or update, and lets you build or use extra API functionality.
You can build a custom module to:
-
Group reusable functions in a common library file. Use custom modules to organize helper functions or custom APIs into reusable sections—then load them in your entry point script.
-
Add custom modules to SuiteApps and share them with third parties.
-
Import a third-party API.
-
Separate utilities from business logic.
Custom modules aren’t supported in bundle installation scripts.
To see how a custom module is built, check out SuiteScript 2.x Anatomy of a Custom Module Script. You can also follow the SuiteScript 2.x Custom Module Tutorial.
While building your custom module, these topics might help:
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. Always use define when making custom modules, entry point scripts, or referencing script files with a relative path.
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 regular and custom JSDoc tags to your module scripts. Use @NApiVersion
and @NModuleScope
to show the API version and module scope. For non-entry modules, @NApiVersion
shows which SuiteScript version you’re using—and prevents problems if a referencing script is on a different version. @NModuleScope
controls whether other scripts and accounts can access your module. To learn more, see Controlling Access to Scripts and Custom Modules.
For info on JSDoc tags, see SuiteScript 2.x 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 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
- SuiteScript 2.x
- SuiteScript 2.x API Introduction
- SuiteScript 1.0 to SuiteScript 2.x API Map
- SuiteScript 2.x Script Types
- SuiteScript 2.x Global Objects
- SuiteScript 2.x Modules
- SuiteScript 2.x Record Actions and Macros
- SuiteScript 2.x JSDoc Validation
- SuiteScript 2.x Entry Point Script Creation and Deployment
- SuiteScript 2.x Scripting Records and Subrecords
- SuiteScript 2.x Custom Pages