Script modules are used to define commonly used library functions. Modules can be called from pre work, post work like server environment, or form and validation rule like client environment.
Modules are always executed in an isolated environment, and do not automatically import any process related variable.
Define a Script Module
- Click "+" icon from "Script Modules"
- Specify the module name. Because the module name is used in a script environment, whitespace or other punctuation chars cannot be used for it.
- Modify the module content as a following script:
function privateSum(a,b) { return a+b; } function publicSum(a,b) { return privateSum(a,b); } exports.sum = publicSum;
Parameter Types
Module parameters must be serializable primitive types like string, date, number or object. Other complex types like xml node or functions cannot be used as parameters.
Exporting Module Functions
Modules may contain one or more functions to structure content and reusability, but not all functions are exported to the outside of a module. If you want to expose a function to the outside world, function must be added to "exports" object.
Calling Module Function
Module functions should be called in "ModuleName.FunctionName(arguments)" syntax. For the example above, that function is called as following:
var result = MyModule.sum(1,2);
Client Side Module Calls
Modules are always executed as synchronous context in server environment, but because of the browser limitations, client side modules can be renamed as "functionAsync" and return a javascript promise object to support asynchronous context. For example, the same module as the one above, can be called as following:
MyModule.sumAsync(1,2).then(function(result) { // result = 3 });