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.

·3 min read·View Oracle Docs

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 @NApiVersion to specify the SuiteScript version and @NModuleScope to define access levels of your module.

Example of a Custom Module Script

suitescript
1/**
2 * phoneCall.js
3 * @NApiVersion 2.x
4 * @NModuleScope Public
5 */
6
7define (['N/record'], function(record) {
8 // Your logic here
9});

Using Your Custom Module

After creating your custom module, reference it in another script. Follow these steps:

  1. Create a script to load and run your custom module using the require function.
  2. Upload both your custom module and entry point script to the NetSuite File Cabinet under SuiteScripts.
  3. 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 define and require functions 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?
No, custom modules are not supported in bundle installation scripts.
What is required to correctly upload custom modules and entry point scripts in NetSuite?
You need to upload both the custom module and the entry point script to the NetSuite File Cabinet under SuiteScripts, and create a script record and deployment record for the entry point script.
What function is used to create a custom module in SuiteScript 2.x?
The 'define' function is used to create custom modules in SuiteScript 2.x, which facilitates loading other modules and managing dependencies.
What is the importance of using JSDoc Tags in custom modules?
JSDoc Tags, such as '@NApiVersion' and '@NModuleScope', are important for specifying the SuiteScript version and defining access levels for your module, ensuring proper documentation and module scope setting.
Source: Using Your Custom Module Oracle NetSuite Help Center. This article was generated from official Oracle documentation and enriched with additional context and best practices.

Was this article helpful?

More in Platform

View all Platform articles →