require Function

The require function is a global object that implements the require() Module Loader interface for SuiteScript 2.x. It conforms to the Asynchronous Module Definition (AMD) specification. When NetSuite executes the require function, it executes the callback function and loads the dependencies when they are needed.

This function executes asynchronously on the client and synchronously on the server.

Note:

Only use the require function if you want to load an existing module. If you want to create an entry point script or a new custom module, use the define Object.

Use the require function to progressively load native SuiteScript 2.x modules and custom modules. When you use the require function, dependencies are not loaded until they are needed which can help increase script performance. For example, if you include lib1 as a dependency in your require function, when you call a method that is included in lib1, the Module Loader then loads the module and executes the method. For code samples on how the require function progressively loads modules, see require([dependencies,] callback) and Custom Modules Frequently Asked Questions.

Type

Name

Return Type / Value Type

Description

Function

require([dependencies,] callback)

void

Loads a SuiteScript 2.x entry point script or a SuiteScript 2.x custom module.

Executes the callback function and loads the dependencies when they are required.

Note:

You can configure a require Object by associating a script to a JSON-formatted configuration file using the @NAmdConfig JSDoc tag. This is helpful to configure the loading of a custom module. Properties that can hold feature metadata, aliases, paths, package, and mapping information related to a module id are supported. For more information about configuring a require Object, see require Configuration.

Related Topics

General Notices