Custom Module Usage with SuiteScript 2.x in NetSuite
Learn to create and use custom modules with SuiteScript 2.x, enhancing modularity and reusability in your NetSuite scripts.
TL;DR Opening
Creating and using custom modules with SuiteScript 2.x in NetSuite allows for better code organization, reusability, and modular architecture. This helps streamline development and maintenance of scripts.
What is a Custom Module?
A custom module in SuiteScript 2.x serves as a reusable library of code that can be shared across multiple scripts. By utilizing modules, developers can package functions, manage dependencies, and enhance the maintainability of their code. Here are some core functions you can achieve with custom modules:
- Group Reusable Functions: Collect helper functions into a common library file, improving organization.
- Share with Third Parties: Integrate custom modules into SuiteApps for external sharing.
- Third-party API Import: Easily bring in external APIs that your application may need.
- Separate Utilities from Business Logic: Maintain a clear distinction between business rules and utility functions.
Note: Custom modules are not supported in bundle installation scripts.
Custom Module Prerequisites
Before diving into creating a custom module, familiarize yourself with the following topics:
- [SuiteScript 2.x Script Basics]
- [SuiteScript 2.x Entry Point Script Validation]
- [Module Dependency Paths]
- [Controlling Access to Scripts and Custom Modules]
Creating a Custom Module
When creating a custom module, use the define function. This function facilitates loading other modules and managing dependencies. Your module script must return an object where the typical return value is a function. Here’s the breakdown:
- JSDoc Tags: Use
@NApiVersionto specify the SuiteScript version and@NModuleScopeto define access levels of your module.
Example of a Custom Module Script
1/** 2 * phoneCall.js3 * @NApiVersion 2.x4 * @NModuleScope Public 5 */6 7define (['N/record'], function(record) {8 // Your logic here9});Using Your Custom Module
After creating your custom module, reference it in another script. Follow these steps:
- Create a script to load and run your custom module using the
requirefunction. - Upload both your custom module and entry point script to the NetSuite File Cabinet under SuiteScripts.
- Create a script record and deployment record for the entry point script.
For best practices in naming modules, refer to the section on [Naming a Custom Module].
Callout: Make sure your module and entry point scripts are uploaded correctly to ensure successful execution.
Key Topics for Further Learning
Here are some additional resources to enhance your understanding of SuiteScript 2.x custom modules:
- [Module Dependency Paths]
- [SuiteScript 2.x Script Types]
- [JSDoc Validation in SuiteScript 2.x]
By leveraging custom modules effectively, developers can lead more efficient development processes and create cleaner, modular code that minimizes duplication and encourages reuse.
Key Takeaways
- Custom modules in SuiteScript 2.x enhance code modularity and maintainability.
- Use
defineandrequirefunctions for managing dependencies. - Familiarize yourself with JSDoc for documenting scripts.
- Upload scripts to the NetSuite File Cabinet for effective organization.
- Ensure your scripts are deployed correctly for seamless functionality.
Frequently Asked Questions (4)
Are custom modules supported in bundle installation scripts within NetSuite?
What is required to correctly upload custom modules and entry point scripts in NetSuite?
What function is used to create a custom module in SuiteScript 2.x?
What is the importance of using JSDoc Tags in custom modules?
Was this article helpful?
More in SuiteScript
- SuiteScript 2.1 Enhancements in NetSuite February Updates
SuiteScript 2.1 now supports async features and PATCH method. Discover the latest API and SuiteProcurement improvements.
- Scheduling Map/Reduce Script Deployments in NetSuite
Learn to schedule map/reduce script submissions, including one-time and recurring options in NetSuite.
- Binary File Support in N/https Module for SuiteScript
SuiteScript enhances capabilities with binary file support in the N/https module, allowing improved data handling in external communications.
- API Governance Units Calculation in NetSuite 2026.1
NetSuite 2026.1 introduces examples illustrating API governance unit calculations for both user event and scheduled scripts.
