Function

Function task executes JavaScript or Groovy script.

Input

Attribute
Description

Script Type

JavaScript or Groovy

Function

Script contents

Output

Attribute
Description

ResultValue

The return value from the script, if exists.

UseDataStructure

Map data structure to the return value. This is used at mapping component.

DataStructureId

Data structure id for future mapping.

Example

JavaScript

JDK provides JavaScript engine named Nashorn and this engine is removed since JDK 15. After JDK 15, gravalVM is used as an alternative of Nashorn engine.

And there is a slight change on JavaScript function execution after JDK 8.

Sccript
Result

8

Named function can be executed.

The last function is executed if unnamed function does not exist.

Unnamed function has the highest priority.

9+

Named function cannot be executed.

Unnamed function is executed.

JDK 8

Sccript
Result

function hello () {

return "Hello";

}

Hello

function () {

return "Hello";

}

Hello

function add(a,b) {

return a + b;

}

function a () {

return add(1,2);

}

3.0

function a(a, b) {

return a + b;

}

function () {

return a(1,2);

}

function b() {

return "Hello";

}

3.0

JDK 9+

Sccript
Result

function hello () {

return "Hello";

}

Error

function () {

return "Hello";

}

Hello

function add(a,b) {

return a + b;

}

function () {

return add(1,2);

}

3

Groovy

This is the definition of Groovy (from Wikipedia)

Apache Groovy is a Java-syntax-compatible object-oriented programming language for the Java platform. It is both a static and dynamic language with features similar to those of Python, Ruby, and Smalltalk. It can be used as both a programming language and a scripting language for the Java Platform, is compiled to Java virtual machine (JVM) bytecode, and interoperates seamlessly with other Java code and libraries.

The example script of Groovy is like this.

def func() {
    return "Hello";
}
return func();

Last updated