Script Library
When you need to do the same calculations in a few reactions, you can extract that logic into the script library.
The functions in the script library are shared within the mock service and can be used in any reaction.
The functions can be defined in Javascript and in XQuery.
JS Library
To add JS functions, simply define them in the Javascript
window:
function links(n) { return n * (n-1) / 2; }
Then you can use the functions in any reaction input field that supports scripting.
For example, set the delay proportional to the matched accounts number:
150 * links(accounts.length)
XQ Library
To add an XQ function, define it in the XQuery
window.
The function must be defined with the local:
prefix.
declare function local:links($n as xs:integer) as xs:integer { $n * ($n - 1) div 2 };
The function then can be used in any reaction input field that supports scripting:
150 * local:links(count($accounts))