Portal Community

SetGlobal and GetGlobal

// Any node can set a global variable
ctx.ExecutionMemory.SetGlobal("correlationId", Guid.NewGuid().ToString());

// Any node can read it — no need to be downstream of the writer
var correlationId = ctx.ExecutionMemory.GetGlobal<string>("correlationId");

// Overwrite is supported — last write wins
ctx.ExecutionMemory.SetGlobal("retryCount", 3);
ctx.ExecutionMemory.SetGlobal("retryCount", 4);  // Now 4

// Read as untyped
var raw = ctx.ExecutionMemory.GetGlobal("retryCount");  // Returns object? (boxed int 4)

Difference from nodeOutputs

AttributenodeOutputsglobalVariables
KeynodeId (string)Any string (variable name)
Who writesBaseNodeExecutor (after ExecuteAsync returns)Any executor directly via SetGlobal
Topology constraintOnly upstream nodes' output is meaningfulNone — any node can read any global at any time
Typical usePass data downstream via workflow edgesExecution-wide shared state (flags, counters, context IDs)
HIL serializationYes — included in suspended stateYes — included in suspended state

Common Use Cases

// Use case 1 — Set a flag early, check it in a later branch
// (FeatureFlagNode sets the flag, downstream nodes check it)
ctx.ExecutionMemory.SetGlobal("premiumUser", isPremium);
// ... later, in a conditional node:
var isPremium = ctx.ExecutionMemory.GetGlobal<bool>("premiumUser");

// Use case 2 — Track a counter across loop iterations
var currentCount = ctx.ExecutionMemory.GetGlobal<int>("itemsProcessed");
ctx.ExecutionMemory.SetGlobal("itemsProcessed", currentCount + 1);

// Use case 3 — Propagate a correlation ID through all nodes
// (Set once at the start of the execution, used for tracing)
var corrId = ctx.ExecutionMemory.GetGlobal<string>("correlationId")
    ?? Guid.NewGuid().ToString();
ctx.ExecutionMemory.SetGlobal("correlationId", corrId);
ctx.Observability.Logger.LogInformation("Processing item {CorrelationId}", corrId);

Variable Naming Conventions

ConventionExample
camelCase namespremiumUser, itemsProcessed, correlationId
Prefix for namespace isolationbilling.invoiceId, auth.userId
Avoid generic namesUse orderTotalUsd not total

Accessing via Variable Scoping ($global prefix)

In the expression engine and variable scoping system, global variables set via SetGlobal are accessible using the $global.variableName prefix. See Guide32_VariableScoping for the full variable system.

// Expression engine references global variables with $global prefix
// Example: a condition expression in a gateway node
$global.premiumUser == true

// Another expression: multiply a total by a globally set tax rate
$global.taxRate * $output.invoice-node.subtotal
Global variables are ephemeral within the execution. SetGlobal("key", value) is NOT the same as pinned data. When the execution ends, all global variables are gone. If you need a value in future runs, return it as pinnedData from NodeExecutionResult.Success instead.