> For the complete documentation index, see [llms.txt](https://docs.heisenware.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.heisenware.com/app-builder/build-backend/extension-nodes/filter.md).

# Filter

The filter acts as a conditional gate for your flow. It branches logic or halts it based on a condition and is the primary way to implement `if/else` scenarios in Heisenware.

To add a filter:

1. Click the + icon on the right side of a function output, modifier, or existing filter.
2. Select Filter from the list.
3. Click the new filter box (*Click to edit…*) to open the code editor and write your condition.

<figure><img src="/files/zm2x6quP3bMELcm6wlbK" alt=""><figcaption><p>randomInteger function with filter extension node</p></figcaption></figure>

## How filters work

A filter evaluates a JavaScript expression that must return a boolean value (`true` or `false`). The input value from the preceding output is available as the reserved variable `x`.

Click the filter icon on the left to evaluate the filter manually during development. The last result appears below the expression.

### Logical gate

If the result is `true`, the data passes on to the next node following the filter. If `false`, the flow halts at this point.

<div align="center"><figure><img src="/files/poJAOEoCLXDNFrKQPU1h" alt=""><figcaption></figcaption></figure></div>

### Branching logic

Use the `true` and `false` states of the filter to trigger separate logic paths. For example, use the `true` state to trigger another function.

<figure><img src="/files/1uA9E7OGfl7WLPG6Oal7" alt=""><figcaption></figcaption></figure>

{% hint style="warning" %}

#### Falsy values halt the flow

A filter condition that evaluates to a falsy value (e.g., `false`, `0`, `null`, `""`) stops the execution of the flow.
{% endhint %}

## Filter examples

### Example 1: Threshold monitoring

Checks if a sensor value exceeds a critical limit.

Data:

```json
{
  "temperature": 92.5,
  "unit": "°C"
}
```

Filter content:

```javascript
x.temperature > 90
```

Return of the filter: `true`

<figure><img src="/files/0IWLacfVtCY70lvbAYwX" alt=""><figcaption></figcaption></figure>

### Example 2: Industrial error detection

Inspects a status message for specific keywords like "Error".

Data:

```json
"System Error: PLC Communication Timeout"
```

Filter content:

```javascript
x.includes('Error')
```

Return of the filter: `true`

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

### Example 3: Validating array data

Ensures that an array contains data before the flow processes it.

Data:

```json
[]
```

Filter content:

```javascript
x.length > 0
```

Return of the filter: `false`

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

## Using AI for filters

Use AI chatbots like ChatGPT, Claude, or Gemini to generate complex filter logic. Filters use standard JavaScript, so provide the AI with your data structure to get an immediate result.

For best results, copy this article as context for the AI. Use the Copy button at the top of the page or the Open in ChatGPT / Open in Claude buttons in the top navigation bar.

#### Recommended AI prompt

Copy and paste this prompt into your AI so it understands the Heisenware environment and its variable references.

```
I am working in Heisenware, a node-based visual programming tool for industrial applications. 
I need a "Filter" expression that acts as a conditional gate in a flow.

Full documentation: https://docs.heisenware.com/app-builder/build-backend/extension-nodes/filter.md

Rules:
* A filter is a single JavaScript expression that must return true or false. JSONata is not supported here.
* The input data is referenced as x.
* If the result is falsy, the flow halts at the filter.
* No statements or variable declarations. For multi-step logic, use an IIFE: (() => { ... })().
* Reply with the expression only, no explanation, no markdown fences.

My input data (sample):
[Paste a sample of the data arriving at the filter here.]

My task:
[Describe your condition, e.g., "Only continue if pressure is between 2.0 and 4.5 bar."]
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.heisenware.com/app-builder/build-backend/extension-nodes/filter.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
