Basics
SuiteScript Modules
Using SuiteScript Modules
SuiteScript modules use N/ modules with require for encapsulation.
Introduction to SuiteScript Modules
SuiteScript is a JavaScript-based framework used for extending and customizing NetSuite applications. In SuiteScript, modules are a way to organize and encapsulate your code, making it reusable and maintainable. This is achieved using the N/ modules with the require function.
What is a SuiteScript Module?
A SuiteScript module is a file that contains JavaScript code and exports specific functionality. Modules help in keeping the code organized and make it easier to manage larger projects by breaking them down into smaller, manageable pieces.
Using the require Function
The require function is used to load modules in SuiteScript. This function is similar to the import
statement in other JavaScript environments. It allows you to include the functionality of one module into another.
Defining Your Own Modules
You can define your own modules in SuiteScript by using the define function. This function takes an array of dependencies and a callback function. The callback function is executed once all dependencies are loaded. Here’s an example of how you can define your own module:
Best Practices for Using Modules
- Keep modules focused on a single responsibility to enhance reusability.
- Use descriptive names for modules to make it clear what functionality they provide.
- Leverage the power of native NetSuite modules like N/log, N/record, etc., to minimize the need for custom code.
- Avoid circular dependencies to prevent unexpected behaviors.
Basics
- Previous
- Security Basics
- Next
- Governance