Script
The Script processor allows you to specify your own processor logic for a simple processor using JavaScript or Groovy. The script is entered as an option on the script processor.
Note that it is possible to use a script in a processor that is created in EDQ, so that the script is not easily accessible by the end user of the processor. It is also possible to use script when writing a new processor to add into the processor library - this allows for greater complexity in the script - for example to enable multiple inputs and outputs, options that use Reference Data, and results views.
Use the script processor to define some simple processing logic that cannot be achieved easily using any of the provided processors.
Inputs
Any number of attributes of any type may be input to a Script processor. The selected input attributes are mapped to a JavaScript array named input1
.
Options
Option | Type | Purpose | Default Value |
---|---|---|---|
Result type |
Selection (String / Number / Date / String Array / Number Array / Date Array) |
Determines the type of the output result of the script. Note: If you select an Array type, you must instantiate the array in your script. |
String |
Script |
Script |
The script defining the processor logic. See note below regarding the use of functions, and changing the script language. |
None |
Note:
It is possible to specify a function to be called for each record (as opposed to executing the entire script each time), and to change the language of the script
To set a function include the following line at the top of the script:
#! function : doit
In this script, doit
is the function name; change this to the function name you are using.
To change the language of the script to groovy rather than Javascript, add the line:
#! language : groovy
Outputs
The Script processor supports a single output data attribute only. The type of this attribute is determined by the setting of the Result type option.
The single output must be assigned to the script name output1
.
Note:
Selecting an Array type for your result type does not automatically instantiate the array. Due to the differences between simple data types and array types, the array must be instantiated by your script. Failure to do this will result in a script execution error when the processor is run. Please see Example 1-3 for more details.
Data Attributes
Data attribute | Type | Purpose | Value |
---|---|---|---|
ScriptResult |
Added |
An attribute with the result of the script. |
The value is set by the script. |
Flags
None
Execution
Execution Mode | Supported |
---|---|
Batch |
Yes |
Real-time Monitoring |
Yes |
Real-time Response |
Yes |
Note:
When writing a new processor (which may include the use of script), it is possible to make the processor incompatible with Real-time Response execution, by flagging the processor as one which needs to run to completion (for example a processor that filters records based on a percentage calculated across all records that are processed).
Results Browsing
The Script processor presents no summary statistics on its processing.
In the Data view, each input attribute is shown with the output attributes to the right.
Output Filters
None
Examples
Example 1-1 Script to output a unique identifier
The following example script uses an underlying Java function to generate a unique ID.
output1 = java.util.UUID.randomUUID().toString()
In this case, no input attributes are actually used by the script but a dummy attribute must be input to the Script processor to allow it to run.
Result
Result of Example 1 script
ScriptResult
-
4d8ed32a-4175-409a-a752-3619cf9fbd5a
-
8818e732-f56d-4658-bfd9-93ef7ee639bd
-
4e957a42-6b6c-4669-a7fe-d5c17f1e734f
-
49a658c1-20db-4d3c-81d8-8cc4aa91016b
-
1dc94a3c-ec7c-4191-a199-ce1aa4316404
-
11d3c22f-77cf-4ccc-bbcf-e78ac2ebd227
-
dd698c8d-9bfb-40b5-a5bd-2660787233ec
-
b624911b-9d16-4377-8520-4ab546132dfc
-
7859603f-3348-4bae-ba62-e24daa11c1cd
-
065fcae7-3a71-4683-931a-cd16c8d45d91
-
ecdad97d-6dd2-4556-9f47-76cc9a4d74e9
-
b22b386f-c655-4497-9ee4-a379381201dc
-
7e7b817d-a752-4b9c-98ca-bfd2c85136fa
Example 1-2 Concatenate
The following example script concatenates all input attributes into a single output value, with each attribute value separated by ||:
var res = ''; for (var i = 0; i < input1.length; i++) { if (i > 0) res += '||'; res += input1[i]; } output1 = res;
Result
Title | Forename | Surname | Name |
---|---|---|---|
[Null] |
KAREN LOUSE |
MILLER |
||KAREN LOUISE||MILLER |
MR |
BRIAN MICHAEL |
MILES |
||BRIAN MICHAEL||MILES |
[Null] |
FREDRIK |
MISTANDER |
||FREDRIK||MISTANDER |
MR |
KENNETH |
MIDDLEMASS |
||KENNETH||MIDDLEMASS |
[Null] |
NEIL ALASTAIR |
MITCHELL |
||NEIL ALASTAIR||MITCHELL |
[Null] |
KOKILA RAMESH |
MISTRY |
||KOKILA RAMESH||MISTRY |
[Null] |
ANDREW SIMON |
MICKLEBURGH |
||ANDREW SIMON||MICKLEBURGH |
Example 1-3 Using an Array Result Type
Unlike simple data types, an array variable must always be instantiated before values can be written to it. Failing to do this will result in an error messages similar to the following:
Script execution failed: TypeError: Cannot set property '0.0' of null to '<value>' ([script]#2)
To instantiate your output array, your script must use the new command to allocate memory for the array, as follows:
var output1 = new Array();
Following this statement, the array will be instantiated and available for writing.