Script Invocation Application

Scripting languages such as JavaScript or Python give the process designer the ability to manipulate, transform and convert data easily without the need to compile code. With scripting languages, the modeler can write scripts for string manipulation, formula calculation, etc. Also, scripting languages can be tested on the fly at design time.

The Infinity Script Invocation application allows to create scripts that can access the process instance data. It also allows users to create Java Scripts that execute on activity activation.

Setting Script Invocation Properties

Apart from the common properties, the following property tabs are provided for a Script Invocation application:


Figure: Properties - Script Invocation Application

Parameters

An arbitrary set of Input and Output Parameters can be created. These objects can be accessed by ID from within the script editor.

Configuration

In the Configuration tab you can specify the script code. In case you are working in the Integrator mode, the following checkboxes are available:

The following script languages are supported:

Code completion

The editor provides auto-completion for keywords and parameter definitions.

Auto-completion
Figure: Auto-completion for code keyword

Auto-completion
Figure: Auto-completion for parameter definition

Testing the Configuration

If you have selected JavaScript as source code, the script code can be tested at design time from the Test tab. Note that this tab is not available if you choose Python as script language.

To test your configuration follow the steps below:


Figure: Testing Java Script Execution

Note that only native JavaScript code can be tested successfully in this tab.

Changing the Converter Behavior for XPath Evaluation

The converter behavior concerning the evaluation for XPaths can be adjusted via the property XPath.StrictEvaluation. You can set this property in your carnot.properties file.

In case this property is set to true, which is the default value, strict XPath evaluation will be performed. The following error is thrown in that case and the process is interrupted:

IllegalOperationException: MDL01123 - XPath 'FullName' is not defined.


Figure: XPath evaluation error

If you like to have a warning logged instead and to continue the process, set this property to false.

XPath.StrictEvaluation = false

Examples

JavaScript Example

In the following example we create a process to show how to concatenate two strings using JavaScript code in a Script Invocation application.

The input entered manually by the user is a structured data TwoStrings which contains two string variables (String1 and String2). The output is a primitive data.

The JavaScript code concatenates the text of the two strings and sets the result to the output variable.

To verify the behavior of the JavaScript code at design time, we click the Refresh icon in the Test tab and enter some test data in the Input field. Then we click the Run icon to display the result in the Output field.

After deploying the model and starting the process, we enter two string values.

The output activity displays these text values concatenated.

Using XML attributes in JavaScript

In case a structured data parameter is based on an XSD having attributes, the syntax should follow the format: sdtParam["@attributeName"].

XML attribute example

In this example we have the following employee structured data:

<xs:element name="employee">
   <xs:complexType>
      <xs:sequence>
         <xs:element name="address">
            <xs:complexType>
               <xs:attribute name="city" type="xs:string"></xs:attribute>
               <xs:attribute name="zipCode" type="xs:string"></xs:attribute>
            </xs:complexType>
         </xs:element>
      </xs:sequence>
      <xs:attribute name="name" type="xs:string"></xs:attribute>
   </xs:complexType>
</xs:element>


Figure: Properties - Script Invocation Application

A script application uses this structured type for its in and out parameters:


Figure: Script application parameters using the employee xsd type

The following code contains syntax to use the values of the attributes of the input parameter structured type to assign to the output parameter:

var fullname = EmployeeIn["@firstname"] + " " + EmployeeIn["@lastname"].toUpperCase() + " - ";
var address = EmployeeIn.address["@zipCode"] + " " + EmployeeIn.address["@city"];
OutString = fullname + address;


Figure: JavaScript code for accessing attributes

Our process reads the data for the employee, uses this data in the JavaScript application and finally displays the resulting output data


Figure: Example process

To test this configuration, enter data for the Employee data.


Figure: Enter example data

The result should look similar to the following:


Figure: Output data created by the Script application

Python Example

This example shows how to use Python script code to perform numeric calculation.

We use a structured data with two attributes of type Number (Value1 and Value2), which will be used as input parameters and a primitive data of type Number to be used as output parameter.

Parameters

In the Configuration section, we select Python and enter code to multiply the two input parameters and save the value in the output parameter.

Configuration

The process for this example reads the data for the number values, uses this data in the Python Script application and finally displays the resulting output data.


Figure: Example process for Python example

To test the Python script application, run the process and enter two numbers.


Figure: Enter example data

The last activity shows the expected result.


Figure: Output data created by the Script application