Set Variable
The set variable step stores key-value pairs in the $vars namespace, which persists across the entire workflow execution. The step editor shows a key-value form where you define variable names and their values.
How It Works
Section titled “How It Works”Each set-variable step merges its output into the existing $vars — it doesn’t replace them. This means values accumulate and you can update individual keys without losing others.
First set-variable step — initialize some state:
| Key | Value |
|---|---|
offset | 0 |
hasMore | true |
items | {{ $util.emptyArray }} |
Later set-variable step — update specific keys (the others are preserved):
| Key | Value |
|---|---|
offset | 100 |
items | {{ $vars.items | arrayConcat: fetch-page.body.data }} |
After this, $vars contains { offset: 100, hasMore: true, items: [...] }.
Referencing Earlier Keys in the Same Step
Section titled “Referencing Earlier Keys in the Same Step”Variables in a single set-variable step are resolved top-to-bottom, so any key can reference a key defined above it in the same step via {{ $vars.key }}. This lets you derive several related values from a single base without spreading them across multiple steps.
Compose related URLs from a single base:
| Key | Value |
|---|---|
apiBase | https://api.example.com/{{ $env.STAGE }} |
searchUrl | {{ $vars.apiBase }}/search |
usersUrl | {{ $vars.apiBase }}/users |
ordersUrl | {{ $vars.apiBase }}/orders |
After this single step, $vars.apiBase, $vars.searchUrl, $vars.usersUrl, and $vars.ordersUrl are all set — and changing the stage in one place updates them all.
Snapshot a timestamp once and derive a filename from it:
| Key | Value |
|---|---|
runStartedAt | {{ $util.now }} |
today | {{ $vars.runStartedAt | date: "%Y-%m-%d" }} |
reportFilename | report_{{ $vars.today }}.csv |
Capturing runStartedAt once and reusing it guarantees every derived value is based on the same instant — no risk of $util.now returning a slightly different timestamp on each reference.
Accumulate into an array:
| Key | Value |
|---|---|
tags | {{ $util.emptyArray }} |
allTags | {{ $vars.tags | push: initial.category | push: "automated" }} |
Because resolution is sequential within the step, $vars.tags is [] by the time allTags is computed, so allTags becomes [<category>, "automated"].
Common Patterns
Section titled “Common Patterns”Accumulating inside a for-each loop:
| Key | Value |
|---|---|
processedCount | {{ $vars.processedCount | plus: 1 }} |
Storing computed values for later steps:
| Key | Value |
|---|---|
fullName | {{ initial.firstName }} {{ initial.lastName }} |
isVip | {{ initial.totalOrders | gte: 100 }} |
Access variables anywhere in the workflow:
{{ $vars.processedCount }}{{ $vars.fullName }}