Use Global Functions in a Container
Global functions must be imported into a page (or any container) using the imports section of the container metadata (and its modules property) before the global functions can be used.
layout.json, defined in the same extension where the functions metadata is defined (say, ext-layout), can specify the modules in its imports like this:{
"imports": {
"modules": {
"utils": {
"path": "self:$functions/utils"
},
"dateUtils": {
"path": "self:$functions/dateLocalUtils"
},
"commonUtils": {
"path": "ext-common:$functions/utils"
}
}
}
}The path property uses a scheme for locating the JavaScript resource, particularly functions, using a convention with three elements:
{extId}:{resourceType}/{resourceAlias}The path resolves to the actual require path to the JavaScript module loader.
| Element | Description |
|---|---|
| {extId} |
Refers to the extension the resource belongs to.
|
| {resourceType} |
Uses a special keyword for the
|
| {resourceAlias} |
For global functions,
|
Here's an example of how functions.json, defined under ext-common/ui/self/resources/functions, might look:
{
"commonUtils": {
"path": "utils/common",
"label": "Common Utility Functions",
"referenceable": "extension",
"functions": {
"titleCase": {}
}
}
}For ext-layout to import global functions from ext-common, it must have a dependency on ext-common (see Reference Global Functions in an Expression).
Note:
Thepath property definition for web apps in a visual application is slightly different. See Define Global Functions in a Visual Application.