Portal Community

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 itWorkflow designer via SetVariable nodeBackend engineer via executor C# code
Expression prefix$var.{name}$global.{name} (not the same as $global tenant constants)
MutableYes — multiple SetVariable nodes can update itYes — any executor can call SetGlobal
ScopeOne executionOne execution
Visible to designersYes — declared and managed in the canvasPartially — 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.{name} is null until a SetVariable node sets it. If you reference $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.