Import Modules Using a Global Functions Resource Path

While a JavaScript resource defined within an application can be imported into a container using existing conventions, it is often the case that an extension may want to share it for reuse by downstream extensions.

For example, a top-level extension may have a set of JS modules that are used by business rules associated to layout artifacts. Rather than copy the code for the JavaScript utility resource in every downstream extension that requires the same logic, an extension can use global functions to define the resource and declare the rules for its usage in a functions.json metadata file. This allows a dependent downstream extension to import the JS module and use it with minimal effort.

A downstream extension that extends from an upstream extension can also define its own global functions. Global functions can be defined at each extension level.

As stated, global functions for use within the extension (and its App UIs), or across extensions, must first be declared in a functions.json file, along with a level of access afforded to downstream extensions to the methods the JS module provides.

Note:

The term "global function" refers to its usage as a globally available module and must not be confused with a context such as $global.

Global functions can also be defined in visual applications—but only in a single web application's resources folder, and not at the root/visual app level. See Define Global Functions in a Visual Application.