JavaScript Script Objects can be defined as Functions which can then be referenced inside an XpertScript script. This allows more complex scripting to be written by a person familiar with the JavaScript language and then to make this Function available to the domain expert who can call it from within their XpertScript script. This option in effect enables JavaScript developers to extend the functionality available for XpertScript scripts developers.
The Add Scripting (JavaScript) Tool, under Advanced Tools, has an option to create such functions:
The tool will capture the name, type and parameters of this function. Parameters, and the optional returned value, can be of type Numeric, Boolean, Text, Date & Object.
The tool will then generate a shell JavaScript script Object in which the JavaScript code can be added. An example of a generated function is shown below:
In the following example, the above function is utilised from within an XpertScript script editor:
Note that the defined functions will appear under the User Scripts tab above
The same function can also be called from the JavaScript script editor:
var MyValue = #MyFunction.run(#MyNum.val(),"some text",#MyBool.val(),MyDate.Val());
Functions are not designed to be directly inserted into a Decision Flow Tree since they require parameters to be passed and the returned value to be stored in another Object. However, Functions can be invoked by a tree indirectly via an XpertScript script embedded in the Decision Flow Tree.