$var.{name} — Workflow Variables
$var.{name} accesses mutable execution variables set by SetVariable nodes in the workflow. Unlike $output.{nodeId}, which reads a node's computed output, $var reads explicitly named values that can be updated at any point in the graph by placing a SetVariable node.
How $var Variables Are Set
Workflow variables are populated by the SetVariable built-in node. The designer configures a variable name and a value expression. When the SetVariable node runs, it calls ctx.ExecutionMemory.SetGlobal(name, value) internally.
// SetVariable node configuration (in the node's config panel)
{
"variableName": "selectedRegion",
"valueExpression": "$json.body.region ?? 'us-east-1'"
}
// After this node runs, $var.selectedRegion resolves to the computed value
// Any downstream node can use:
$var.selectedRegion
Expression Examples
// Read a simple string variable
$var.selectedRegion
// Read a variable and use it in a URL template
"https://api.{{$var.selectedRegion}}.example.com/orders"
// Use in a condition
$var.retryCount < 3
// Use in arithmetic
$var.basePrice * 1.2
// Nested object variable
$var.userProfile.role == "admin"
Updating Variables — Multiple SetVariable Nodes
A $var variable can be updated during the execution by placing additional SetVariable nodes further in the graph. Each SetVariable call overwrites the previous value. This enables patterns like counters and accumulators within a single run.
// Pattern: counter incremented by a SetVariable node in a loop
// SetVariable node config — reads current value and increments
{
"variableName": "itemCount",
"valueExpression": "($var.itemCount ?? 0) + 1"
}
// Each time this SetVariable node runs, $var.itemCount increases by 1
$var vs. SetGlobal in Executors
| Attribute | $var.{name} (SetVariable node) | ctx.ExecutionMemory.SetGlobal (executor code) |
|---|---|---|
| Who sets it | Workflow designer via SetVariable node | Backend engineer via executor C# code |
| Expression prefix | $var.{name} | $global.{name} (not the same as $global tenant constants) |
| Mutable | Yes — multiple SetVariable nodes can update it | Yes — any executor can call SetGlobal |
| Scope | One execution | One execution |
| Visible to designers | Yes — declared and managed in the canvas | Partially — visible via expression if name is known |
Lifetime
$var variables are ephemeral — they exist only for the current execution run. They are NOT accessible in future runs. If cross-run persistence is needed, use pinned data.
$var.retryCount in a node that runs before any SetVariable node has set retryCount, the expression evaluates to null. Always place the initializing SetVariable node upstream of any node that reads the variable, and use null-coalescing where appropriate: $var.retryCount ?? 0.