This function is used to execute a script in the Groovy programming language. Groovy is a scripting language that is closely based on Java syntax, but also allows a simplified syntax. It is characterized by its dynamic typing, high execution speed and good integration into the Java Virtual Machine. The Groovy function can be used to program very individual transformations implemented at runtime. It is also suitable for mathematical calculations.
More information about the Groovy programming language is available at http://groovy-lang.org.
The input fields can be used in the script as Groovy variables under the following conditions:
- If an alias is defined for the input field, it defines the Groovy variable name. Valid characters for an alias are uppercase and lowercase letters, numbers and the symbols “_” and “$”. The alias must not start with a number and must not be a Groovy keyword (e.g. “my_InputField1$” is a valid alias). The alias is a valid Groovy identifier name.
- If no alias is defined, then the name of the input field is the Groovy variable name. In that case, it must be a valid Groovy identifier name.
- Additionally, the variable name in the form “_input<i>” can also be used where <i> is the position of the input field. For example, “_input1” can be used for the first input field and “_input2” for the second.
Note: We recommend you use the alias name. As best practice the variable name should be in lower camel case e.g. “myVariable1”. If the name in the input is identical to a class in a standard Java library e.g. “Currency” an alias name is obligatory (otherwise the Groovy script would assign the value to the Java class).
A type can be assigned to each input field that defines the type of the Groovy variable in the script. If necessary, a type conversion of the input data is done before the script is executed (with the exception of Object type, which does no conversion and keeps the input type). This is especially helpful for numerical inputs and calculations.
The following data types exist: double, short, int, long, byte, string, float, object. The default type is string.
|Type||The data type of return value. All of the above data types are possible; the assignment of a type is optional.|
|buffered||If set, the function results are cached and the script is not evaluated for identical input values (default). If not set, the script is always evaluated for all rows. This is necessary if the result depends on the row number or a random number generator.|
|Null default||Defines a fallback value to be used when the incoming value is NULL. If checked, then a specific fallback for the data type used in the function will be used, e.g. empty string for string data type, 0 for integer data type, etc.|
The result of the function is determined in the script with a return statement.
A script that is intended to be interruptible by Integrator Server must use Java’s sleep method, e.g. Thread.sleep(15000). For more information, see https://docs.oracle.com/javase/7/docs/api/java/lang/Thread.html#sleep(long)
Note: for performance reasons, the Groovy function internally buffers the results, so that a script is executed only once for the same set of input values. This may lead to wrong values if the script doesn’t depend only on the input values, e.g. random value functions, use of setProperty()/getProperty(). In this case, a RowNumber function should be added to the input list of the script function so that it is always unique.
Documentation on Groovy syntax and a list of all keywords can be found here.
|Possible valid scripts|
|double OrderValue= OrderQty*_input2;
See also Groovy Job.