# Append to array (/docs/nodes/append-to-array)



The **Append to array** node adds one or more values to a list kept in a variable. It is how a flow collects things as it goes: flags, reasons, matched rules.

## When to use it [#when-to-use-it]

* Gather the results of several branches into one list, such as every risk flag raised.
* Replace hand-written `merge` formulas inside a Calculate node.

## How it works [#how-it-works]

<Diagram node="append-to-array" kind="anatomy" />

1. The node checks the target variable: it must be a list, or not exist yet.
2. Each value expression is evaluated.
3. The values are appended, in order, to a copy of the list (created empty on first use) and the result is stored back.

## Ports [#ports]

| Port   | Taken when                         |
| ------ | ---------------------------------- |
| `Next` | Always, after the list is updated. |

## Configuration [#configuration]

| Field    | What it does                                               |
| -------- | ---------------------------------------------------------- |
| Name     | Label shown on the canvas and in the trace.                |
| Variable | The list variable. A plain name, not a dotted path.        |
| Values   | One or more values (an expression or a literal) to append. |

## What it writes [#what-it-writes]

The list variable, longer than before: `vars.flags`. The trace shows how many items were appended and the new length.

## In a real flow [#in-a-real-flow]

<Diagram node="append-to-array" kind="example" />

When the amount is large, a flag is appended to `flags`. Both paths reach the output, which returns whatever the list holds, possibly empty.

## When it fails [#when-it-fails]

* The variable already holds something that is not a list: `VARIABLE_NOT_ARRAY`. The node refuses to guess instead of coercing it.
* A value expression fails: `EXPRESSION_FAILED`.
* A dotted variable name is an error; nesting belongs in the Output mapping. No values is a warning.

## Good to know [#good-to-know]

* Branches that skip the node simply leave the list untouched, so downstream nodes should expect it to be missing or empty.

## Related [#related]

* [Calculate](/docs/nodes/calculate)
* [Output](/docs/nodes/output)
