5.8 Workflow Variables
In Pop’s visual workflow system, Variables enable cross-node data sharing, state tracking, loop accumulation, conditional logic, and contextual storage.
The variable system allows you to build dynamic, flexible, and programmable complex flows.
This chapter covers:
- What workflow variables are
- Types of variables
- How to read and write variables
- How to use variables in PSL
- Common use cases
- Best practices and considerations
🧩 1. What Are Workflow Variables?
Workflow variables are a global data storage area accessible throughout a workflow run.
They have:
- Cross-node scope
- Lifecycle spanning the entire execution
- Readable and writable
- Suitable for state flags, summaries, intermediate results, accumulations, etc.
Pop automatically maintains variables, which can be accessed and modified through PSL, Script nodes, Logic nodes, AI nodes, HTTP nodes, and more.
🗂 2. Types of Variables
Pop currently provides three major categories of workflow variables:
| Type | Example | Purpose |
|---|---|---|
| Input variables | input.value.title |
User-provided workflow inputs |
| Node variables | nodes[n].output.xxx |
Output from executed nodes |
| Global variables | globals.set("key", value) |
Shareable, writable global data |
Relationship:
input → nodes → globals
Globals are writable and serve as the core persistent storage during execution.
🧰 3. Input Variables (input)
Input variables come from the Entry Node.
Access:
input.value.name;
input.value.file;
input.value.settings;
Characteristics:
- Read-only
- Provided at execution time
- Ideal as initial workflow data
🔗 4. Node Variables (nodes)
Each node produces an output after execution.
You can access it via:
Method 1: By Node ID (index)
nodes[3].output;
Method 2: By Serial Number (recommended)
nodes.sn(12).output.result;
Advantages:
- Does not break when canvas layout changes
- More stable across versions
Examples:
nodes.sn(5).output.text
nodes.sn(7).output.json.data
🌍 5. Global Variables (globals) — The Core Variable System
Global variables are the only writable variable type, enabling cross-node data sharing.
1. Write data
globals.set("summary", "Generated summary text");
globals.set("items", [1, 2, 3]);
globals.set("status", { step: 2, message: "OK" });
2. Read data
globals.value.summary;
globals.value.items;
3. Overwrite behavior
Global variables overwrite when written again:
globals.set("count", globals.value.count + 1);
This is ideal for loops, counters, accumulated data, and dynamic states.
✨ 6. Using Variables in PSL
Nearly all variable operations can be done through PSL.
1. Read input
const name = input.value.name;
2. Read node output
const data = nodes.sn(10).output.json;
3. Write global variables
globals.set("result", data.processed);
4. Check if variable exists
if (globals.value.cache) {
return globals.value.cache;
}
🔄 7. Variable Lifecycle
Variables remain valid for a single workflow execution:
- Workflow starts → Variables initialized
- Nodes execute → Outputs stored in
nodes - Scripts/AI/Logic nodes write to
globals - Workflow ends → Final outputs returned
Variables do not persist across workflow runs.
📘 8. Typical Use Cases
✔ 1. Share data across nodes
AI summary → global variable → consumed by later nodes
✔ 2. Loop accumulation
globals.set("items", [...globals.value.items, newItem])
✔ 3. Cache results
Avoid repeated expensive AI or HTTP calls:
if (globals.value.cache) return globals.value.cache;
✔ 4. Conditional logic
if (globals.value.score > 60) ...
✔ 5. Aggregate multiple node outputs
globals.set("final", {
a: nodes.sn(3).output.x,
b: nodes.sn(7).output.y,
});
⚠️ 9. Best Practices & Notes
1. Keep variable names consistent
Recommended:
snake_case
or
lowerCamelCase
Examples:
user_info
report_items
summaryText
2. Avoid storing large binary files
Do not store:
- PDF file data
- Image buffers
- Large CSV raw content
This may harm performance.
Use:
- File nodes to store
- Globals store only the path or reference
3. Avoid name conflicts
Do not repeat variable names within the same workflow.
4. Don't abuse globals
Use node connections when possible.
Globals should be used for:
- Loops
- Conditions
- State
- Dynamic logic
🎯 10. Summary
Workflow variables elevate Pop workflows from “linear flows” to “programmable automation systems.”
With variables, you can:
- Share state across nodes
- Implement loops and decision logic
- Build complex pipelines
- Create reusable, dynamic workflow behaviors