# Function

Function task executes JavaScript or Groovy script.

![](https://support.xnarum.com/download/manuals/ISM-Manual-2023.fld/image326.png)

## **Input**

&#x20;

<table><thead><tr><th width="204">Attribute</th><th>Description</th></tr></thead><tbody><tr><td>Script Type</td><td>JavaScript or Groovy</td></tr><tr><td>Function</td><td>Script contents</td></tr></tbody></table>

&#x20;

## **Output**

&#x20;

<table><thead><tr><th width="207">Attribute</th><th>Description</th></tr></thead><tbody><tr><td>ResultValue</td><td>The return value from the script, if exists.</td></tr><tr><td>UseDataStructure</td><td>Map data structure to the return value. This is used at mapping component.</td></tr><tr><td>DataStructureId</td><td>Data structure id for future mapping.</td></tr></tbody></table>

&#x20;

## **Example**

&#x20;

### **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.

<table><thead><tr><th width="158">Sccript</th><th>Result</th></tr></thead><tbody><tr><td>8</td><td><p>Named function can be executed.</p><p>The last function is executed if unnamed function does not exist.</p><p>Unnamed function has the highest priority.</p></td></tr><tr><td>9+</td><td><p>Named function cannot be executed.</p><p>Unnamed function is executed.</p></td></tr></tbody></table>

&#x20;

#### JDK 8

<table><thead><tr><th width="368">Sccript</th><th>Result</th></tr></thead><tbody><tr><td><p>function hello () {</p><p>    return "Hello";</p><p>}</p></td><td>Hello</td></tr><tr><td><p>function () {</p><p>    return "Hello";</p><p>}</p></td><td>Hello</td></tr><tr><td><p>function add(a,b) {</p><p>    return a + b;</p><p>}</p><p>function a () {</p><p>    return add(1,2);</p><p>}</p></td><td>3.0</td></tr><tr><td><p>function a(a, b) {</p><p>return a + b;</p><p>}</p><p> </p><p>function () {</p><p>  return a(1,2);</p><p>}</p><p> </p><p>function b() {</p><p>return "Hello";</p><p>}</p></td><td>3.0</td></tr></tbody></table>

#### JDK 9+

<table><thead><tr><th width="370">Sccript</th><th>Result</th></tr></thead><tbody><tr><td><p>function hello () {</p><p>    return "Hello";</p><p>}</p></td><td>Error</td></tr><tr><td><p>function () {</p><p>    return "Hello";</p><p>}</p></td><td>Hello</td></tr><tr><td><p>function add(a,b) {</p><p>    return a + b;</p><p>}</p><p>function () {</p><p>    return add(1,2);</p><p>}</p></td><td>3</td></tr></tbody></table>

&#x20;

### **Groovy**

This is the definition of Groovy (from Wikipedia)

| Apache Groovy is a [Java](https://en.wikipedia.org/wiki/Java_\(programming_language\))-syntax-compatible [object-oriented](https://en.wikipedia.org/wiki/Object-oriented_programming) [programming language](https://en.wikipedia.org/wiki/Programming_language) for the [Java platform](https://en.wikipedia.org/wiki/Java_\(software_platform\)). It is both a static and [dynamic](https://en.wikipedia.org/wiki/Dynamic_programming_language) language with features similar to those of [Python](https://en.wikipedia.org/wiki/Python_\(programming_language\)), [Ruby](https://en.wikipedia.org/wiki/Ruby_\(programming_language\)), and [Smalltalk](https://en.wikipedia.org/wiki/Smalltalk). It can be used as both a [programming language](https://en.wikipedia.org/wiki/Programming_language) and a [scripting language](https://en.wikipedia.org/wiki/Scripting_language) for the Java Platform, is compiled to [Java virtual machine](https://en.wikipedia.org/wiki/Java_virtual_machine) (JVM) [bytecode](https://en.wikipedia.org/wiki/Bytecode), and interoperates seamlessly with other Java code and [libraries](https://en.wikipedia.org/wiki/Library_\(computing\)). |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

The example script of Groovy is like this.

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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ism-docs.xnarum.com/tasks/others/function.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
