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 Stardust 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.
Apart from the common properties, the following property tabs are provided for a Script Invocation application:
Figure: Properties - Script Invocation Application
An arbitrary set of Input and Output Parameters can be created. These objects can be accessed by ID from within the script editor.
Figure: Parameter Mapping
Primitive, choose the
Primitive Type from the provided drop-down list.
Figure: Primitive Data
Structured Data, choose the
Structured Type from the current model or another model from the provided drop-down list.
Figure: Structured Data
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:
Figure: Configuration - JavaScript
Figure: Configuration - Python
The editor provides auto-completion for keywords and parameter definitions.
Figure: Auto-completion for code keyword
Figure: Auto-completion for parameter definition
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.
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
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.

In case a structured data parameter is based on an XSD having attributes, the syntax should follow the format: sdtParam["@attributeName"].
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
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.

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

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