Custom Module Development Using SuiteScript 2.x
Learn to create custom modules in SuiteScript 2.x for reusable functions, API integration, and better code organization.
Creating a custom module with SuiteScript 2.x allows developers to build modular, reusable code that enhances functionality and promotes better organization. Custom modules can encapsulate logic and functions to be shared across scripts, making development more efficient and manageable.
What Are Custom Modules?
Custom modules are specialized scripts that can group reusable functions into library files. By encapsulating functionalities within a module, developers can keep their codebase clean and modular, aiding in maintenance and readability. Here are some primary uses for custom modules:
- Reusable Functions: Create libraries that group common helper functions or custom APIs, which can easily be invoked from entry point scripts.
- Integration with SuiteApps: Custom modules can be included in SuiteApps, enabling developers to distribute enhanced functionality to third parties.
- Third-Party APIs: Import and integrate third-party API functionalities directly into your SuiteScripts.
- Separation of Logic: Distinguish between utilities (helper functions) and business logic, which can improve code clarity.
Note: Custom modules cannot be utilized in bundle installation scripts.
Prerequisites for Creating Custom Modules
Before diving into custom module development, familiarize yourself with the following topics:
- SuiteScript 2.x Script Basics
- Entry Point Script Validation
- Global Objects in SuiteScript 2.x
- Module Dependency Paths
- Controlling Access
Steps to Create a Custom Module
Creating a custom module requires the use of the define function which is a standard practice for all SuiteScript modules. Here's a brief overview:
- Define the Module: Use
defineto specify your module's dependencies and the associated callback function. - Return an Object: Each module should return an object. This might typically be a function that gets executed in the context of the script that calls it.
- JSDoc Tags: Utilize JSDoc tags like
@NApiVersionand@NModuleScopeto clarify the API version in use and control access to your module. For detailed information on formatting, refer to SuiteScript 2.x JSDoc Validation.
Code Sample: Basic Custom Module Structure
Here’s an example of a basic custom module:
1/** 2 * myModule.js 3 * @NApiVersion 2.x 4 * @NModuleScope Public 5 */6 7define(['N/record'], function(record) {8 function createRecord(type, properties) {9 var newRecord = record.create({10 type: type,11 isDynamic: true12 });13 // Set record properties14 for (var prop in properties) {15 newRecord.setValue({16 fieldId: prop,17 value: properties[prop]18 });19 }20 return newRecord.save();21 }22 return {23 createRecord: createRecord24 };25});Using Your Custom Module
To utilize your newly created module, create another script to reference it:
- Reference Using the Require Function: Load your custom module using an absolute path with the
requirefunction. - Deploy the Scripts: Both the custom module and the entry point script must be uploaded to the NetSuite File Cabinet under SuiteScripts.
- Create Script and Deployment Records: For any entry point referencing your module, ensure to create the necessary script records and deployment records.
For a better understanding of the custom module naming conventions and best practices, review the related tutorials and documentation entries.
Key Takeaways
- Custom modules enhance code organization and reusability in SuiteScript 2.x.
- Use the
definemethod to create and manage module dependencies effectively. - Always implement JSDoc tags to facilitate compatibility and access control.
- Custom modules allow for better separation of business logic from utility functions.
Source: This article is based on Oracle's official NetSuite documentation.
Frequently Asked Questions (4)
Can custom modules be used in bundle installation scripts?
What are the prerequisites to start developing custom modules in SuiteScript 2.x?
How do you define a custom module in SuiteScript 2.x?
What steps must be taken after creating a custom module to ensure it's used properly?
Was this article helpful?
More in General
- Payment Date Prediction Feature in NetSuite
Payment Date Prediction in NetSuite utilizes machine learning to enhance financial planning by predicting invoice payment dates.
- NetSuite Ship Central Enhancements for Packing & Shipping
NetSuite Ship Central features enhance packing and shipping operations for improved efficiency and accuracy.
- New Role Setup for NetSuite AI Connector Service in 2026.1
The 2026.1 release adds a new role requirement for the NetSuite AI Connector Service, streamlining custom tool development.
- Generative AI Features in NetSuite 2026.1
Discover new generative AI features in NetSuite 2026.1, enhancing reporting, search, predictions, and development productivity.
Advertising
Reach General Professionals
Put your product in front of NetSuite experts who work with General every day.
Sponsor This Category