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

This node enables lightweight, inline scripting for **custom transformations, calculations, and conditional logic** without requiring Java code or external libraries.

***

### 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 simple scripting needs

Typical use cases include:

* Calculating derived values
* Transforming data formats
* Applying custom validation or conditional rules
* Manipulating arrays or object structures

***

### Install JavaScript Node Extension

Before using the JavaScript Node, the extension must be **installed and enabled** in 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 application

Once installed, the JavaScript Node becomes available in the **diagram palette** like any other activity node.

<figure><img src="https://2015371994-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMpDjHWFRUtZ5nJcSfVXd%2Fuploads%2FX2Ka3nCi8SYf6I8S6sXH%2Fimage.png?alt=media&#x26;token=1cb17835-57ff-47a2-8430-89da237380bb" alt=""><figcaption></figcaption></figure>

***

### Writing JavaScript Logic

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

#### Function Signature

Users must define the logic using the following function signature:

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

* `input` contains the mapped Business Objects
* The function must return a variable named **answered**
* The returned value becomes the node’s output

<figure><img src="https://2015371994-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMpDjHWFRUtZ5nJcSfVXd%2Fuploads%2Fbh7csqpIatMK0mN7g39X%2Fimage.png?alt=media&#x26;token=e3831af4-c7f3-4e2b-b61f-aa93099e9a24" alt=""><figcaption></figcaption></figure>

***

### Input Mapping (Business Objects)

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

Steps:

1. Open **Mapping Parameter**
2. Add all required Business Objects under **Input Variable**
3. Use the **lookup** option to select existing Business Objects

<figure><img src="https://2015371994-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMpDjHWFRUtZ5nJcSfVXd%2Fuploads%2FpnBMQUgrTKvxDeoxur4D%2Fimage.png?alt=media&#x26;token=7312f683-023c-479d-990c-5ce0010362fd" alt=""><figcaption></figcaption></figure>

The mapped Business Objects are passed into the JavaScript function via the `input` parameter.

***

### Output Mapping

The output of the JavaScript Node must be returned using the variable named **answered**.

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

<figure><img src="https://2015371994-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMpDjHWFRUtZ5nJcSfVXd%2Fuploads%2F80ujDDFCzwWAqDND1jGR%2Fimage.png?alt=media&#x26;token=d2b5b5ae-1085-4bca-a100-1fe6b3c49363" alt=""><figcaption></figcaption></figure>

***

### Using JavaScript Results in Flow Logic

Common integration patterns include:

* Transforming data before a Database or Web Service Task
* Calculating intermediate values for decision logic
* Feeding processed data into a **Gateway Node**
* Preparing response structures for UX/UI

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

***

### Best Practices

* Use JavaScript Node for **lightweight logic only**
* Keep scripts readable and maintainable
* Avoid complex business logic—use Microflow structure where possible
* Always return data as **answered**
* Validate and handle null or missing input values

***

### JavaScript Node vs Java Task

| JavaScript Node       | Java Task                     |
| --------------------- | ----------------------------- |
| Lightweight scripting | Full Java implementation      |
| No external JARs      | Requires JAR packaging        |
| Faster setup          | More flexible & powerful      |
| Best for small logic  | Best for complex integrations |

***

### Summary

The **JavaScript Node** is a built‑in Custom Extension that enables **inline scripting** using JavaScript within ONEWEB Microflows.

With the JavaScript Node, developers can:

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

This node is ideal for **data transformation and lightweight business logic** 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/building-apps/integrations/develop-integration-with-oneweb-microflow/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.
