# JavaScript Node

The **JavaScript Node** is a built‑in **Custom Extension** provided by ONEWEB that allows developers to execute **JavaScript logic** on data contained within **Business Objects (BO)** during **Microflow** or **Process Flow** execution.

This node enables **lightweight, inline scripting** for custom transformations, calculations, and conditional logic, without the need to create Java Tasks or manage external libraries.

JavaScript Node is intended for **simple, localized logic** that complements the visual flow design.

***

### Purpose of JavaScript Node

The JavaScript Node is designed to:

* Execute custom JavaScript logic within a flow
* Perform data transformation or calculation on Business Objects
* Implement logic that is difficult or verbose using standard nodes
* Avoid creating Java Tasks for lightweight scripting needs

#### Typical Use Cases

* Calculating derived or intermediate values
* Transforming data formats (e.g. restructuring objects, formatting values)
* Applying custom validation or conditional rules
* Manipulating arrays or object structures

JavaScript Node allows developers to extend Microflows with minimal code while preserving a low‑code design approach.

***

### Installing the JavaScript Node Extension

Before the JavaScript Node can be used, the extension must be **installed and enabled** for the application.

To install the extension:

* Follow the steps described in **Section 6.4.16 – Custom Extensions**
* Install and enable the **JavaScript Node** extension for the target application

Once installed:

* The JavaScript Node appears in the **diagram palette**
* It can be used like any other standard activity node in Microflow or Process Designer

<figure><img src="/files/Ug6GThHUQ8xLY3Nunwwe" alt=""><figcaption></figcaption></figure>

***

### Writing JavaScript Logic

JavaScript logic is defined in the **Extension Properties** of the JavaScript Node.

#### Function Signature

All JavaScript logic must follow the required function signature:

```
function execute(input) {
    // custom logic here
    return answered;
}
```

Where:

* `input` contains the mapped **Business Objects**
* The function **must return a variable named `answered`**
* The returned value becomes the **output of the JavaScript Node**

This strict contract ensures consistent integration with downstream flow logic.

<figure><img src="/files/tk2MgoXxy2Xcb8fk5FCo" alt=""><figcaption></figcaption></figure>

***

### Input Mapping (Business Objects)

All Business Objects that need to be processed by the JavaScript Node must be mapped as **input variables**.

Input mapping allows developers to:

* Select one or more Business Objects as inputs
* Pass structured data into the JavaScript function via the `input` parameter

Mapped Business Objects become accessible inside the JavaScript logic for processing and transformation.

<figure><img src="/files/2dH4dmR1Vf8KbnB1HbSv" alt=""><figcaption></figcaption></figure>

***

### Output Mapping

The output of the JavaScript Node is defined by the returned variable **`answered`**.

Key characteristics:

* The output variable name is always **`answered`**
* Output data is available under the **Output Variable Object**
* Output values can be mapped to:
  * Downstream Business Objects
  * Gateway conditions
  * UI components
  * Database or Web Service tasks

This makes the JavaScript Node suitable for inline data enrichment and preparation.

<figure><img src="/files/iTQ0UskGg1mIKFdAp7ld" alt=""><figcaption></figcaption></figure>

***

### Using JavaScript Results in Flow Logic

Common integration patterns involving the JavaScript Node include:

* Transforming data before a Database or Web Service Task
* Calculating intermediate values used by a Gateway Node
* Preparing response data for UI or API output
* Enriching Business Object data during flow execution

The JavaScript Node integrates naturally into both **Microflow** and **Process Flow** execution models.

***

### Best Practices

To ensure maintainable and reliable scripting within Microflows:

* Use JavaScript Node for **lightweight logic only**
* Keep scripts short, readable, and well‑structured
* Avoid complex business logic—use Microflow structure or Java Nodes instead
* Always return output using the `answered` variable
* Validate and handle null or missing input values gracefully

Following these practices keeps Microflows clean and predictable.

***

### Summary

The **JavaScript Node** is a built‑in Custom Extension that enables **inline JavaScript execution** within ONEWEB Microflows and Processes.

With JavaScript Node, developers can:

* Execute custom JavaScript logic
* Transform and enrich Business Object data
* Implement flexible, fast‑iteration logic
* Avoid unnecessary Java development for simple cases

JavaScript Node is ideal for **data transformation and lightweight logic**, providing a practical balance between low‑code configuration and scripting flexibility in modern integration workflows.


---

# 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://docs.onewebstack.com/oneweb-platform-th/designer-reference/microflow-designer/javascript-node.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.
