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.
Source: This article is based on Oracle's official NetSuite documentation.
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 Platform
- Style Object Members for Workbook API in NetSuite
The Style object provides customizable properties for workbook formatting in NetSuite, enhancing report and visualization functionality.
- Asynchronous HTTP Requests with SuiteScript Promises
Use SuiteScript to send asynchronous HTTP requests with promises for efficient error handling and response processing.
- Setting Sublist Field Values in SuiteScript
Set values for sublist fields in SuiteScript using the setSublistValue method. Understand required parameters and error handling.
- In This Help Topic
Explore N/log module guidelines, log levels, and script execution logs for efficient logging in SuiteScript.
Advertising
Reach Platform Professionals
Put your product in front of NetSuite experts who work with Platform every day.
Sponsor This Category