HELP!

User Defined JavaScript Functions

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:

image descr

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.

image descr

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:

image descr

  • The first (comment) line in the script uses special designations (such as formula:) which are recognised by the XpertScript editor.
  • The special params array is used to access the values of any parameters passed by the call to the function.
  • The return statement is used to pass a value back to the function caller.

In the following example, the above function is utilised from within an XpertScript script editor:

image descr

Note that the defined functions will appear under the User Scripts tab above

image descr

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.

image descr

On This Page