Module Dependency Paths
To specify module paths or names, use the define Object or require Function.
SuiteScript supports the following path types:
Path Type |
Description |
---|---|
Use an absolute path to start from the root folder in the File Cabinet. Absolute paths start with a forward slash (/), like "/SuiteScripts/MyApp/Util". |
|
Relative paths start from the dependent module’s location, so you have more flexibility when moving nested folders around in the File Cabinet. Relative paths start with a period (".") or two periods (".."). For example: if your module is in "/SuiteScripts/MyApp", the relative path to a sibling file is "./Util", which is the same as "/SuiteScripts/MyApp/Util".
Note:
Don’t use relative paths in global contexts. |
|
A bundle virtual path points to a File Cabinet location using a valid bundle ID. Bundle virtual paths start with a forward slash followed by a period (/.). For example: /.bundle/<bundle id>/SS2_CustomModuleTest.js/ |
You can also reference modules using custom module names—a global identifier that lets you refer to a module by name instead of by path. For more, see Naming a Custom Module.
Absolute Paths
Don’t use file extensions in the path.
Start absolute paths with a "/" to point to the top-level File Cabinet directory. Remember, files follow their parent folders’ restrictions, so make sure referenced library files are available to the right users.
In the following example, the Module Loader expects the custom module files lib1.js
and lib2.js
to be located in the SuiteScripts
top-level directory in the File Cabinet.
// myModule.js
define(['/SuiteScripts/lib1', '/SuiteScripts/lib2'], // myModule has a dependency on modules lib1 and lib2
...
);
Relative Paths
Don’t use file extensions in the path. Make sure library files are available to users who need them.
You can use relative paths to point to modules in subfolders from your current module’s location.
In the following example, the Module Loader expects the custom module files lib1.js
and lib2.js
to be located in the lib
subdirectory, the same File Cabinet directory that contains myModule.js
.
// myModule.js
define(['./lib/lib1', './lib/lib2'], // myModule has a dependency on modules lib1 and lib2
...
);
Bundle Virtual Paths
Don’t use file extensions in the path.
Use a bundle virtual path, starting with a forward slash followed by a period ("/."), to point to a bundle File Cabinet location. You’ll need a valid bundle ID.
In the following example, the Module Loader is looking for common libraries in shared bundles.
// myModule.js
require(['/.bundle/101'], // myModule has a dependency on modules with the bundle id 100 and 101
...
);
Sometimes, a virtual path helps if a bundle is moved or its ID changes. When a bundle’s deprecated or copied, SuiteScript 2.x checks the chain and looks for the file in several places. If a bundle’s replaced with a new version (and new ID), scripts using the old path in the target account switch to the new bundle’s ID—the virtual path resolves it automatically.
You can’t use the source account bundle ID for a virtual bundle path, because the path depends on a real file path for an existing bundle—which doesn’t exist at creation in the source account.