Use scripts in processes

Define the scripting language

How you define your scripting language depends on how you implement scripting.

When scripting in process actions, define the scripting language in the Scripting Language parameter.

scripting in process language

When writing scripts in text fields, such as in define the scripting language with special syntax: %e(<language>){<script>}e(<language>)%

The four scripting languages are expressed as follows:

%e(rhino){...}e(rhino)%
%e(nashorn){...}e(nashorn)%
%e(jython){...}e(jython)%
%e(groovy){...}e(groovy)%

Use scripts in conditions

Conditions determine integration flow execution. You can use scripts on execution conditions, which are scripts that return a Boolean value.

The default scripting language for execution conditions is JavaScript (Rhino). The interpreter automatically adds %e(rhino){…​}e(rhino)% script delimiting tags around the conditions code.

Execution conditions in bind links use different tags that allows them to recognize bind variables: %b(rhino){...}b(rhino)%.

You can only use scripts in execution conditions. Generation conditions use XPath instead.

Examples

Complex expression

The following script execution condition is written in JavaScript. It retrieves a MYVARIABLE session variable, checks its contents, and returns a Boolean value with the __ctx__.retvalue context variable.

%e(rhino){
    myVarValue = '${~/MYVARIABLE}$';
    if (myVarValue.substring(0,1).equals(`R')) {
        __ctx__.retValue = 'true';
        }
    else {
        __ctx__.retValue = 'false';
    }
}e(rhino)%

Bind expression

This example is an execution condition for a bind link. It uses the tags for bind variables, and evaluates the condition as JavaScript with the Rhino engine.

%b(rhino){":{val}:" != "1"}b(rhino)%

For a longer explanation of the example, see the page about execution flow.

Use additional libraries

The xDI Runtime comes with certain libraries, but you can add additional libraries and classes to use in a scripting process action. You must add the libraries to a module, and configure the process action to use that module.

Additional scripting libraries have two constraints:

  • You can only assign modules in scripting actions. You cannot assign them for scripts in text fields.

  • You must import the module from within the script directly to use third-party jython and groovy libraries, or to use the java.lang.Class.forName function to search for a class.

To learn about using additional libraries in scripting, see Use additional libraries for scripts.