Custom Variables

Overview

Custom Variables allow you to create, manage, and manipulate data throughout your workflows. They support different scopes (global, workflow, step), types, and transformations for flexible data handling.

circle-info

📦 Purpose

Use Custom Variables to:

  • Store intermediate values

  • Pass data between steps

  • Manage configuration

  • Create reusable data structures

  • Track state across workflow


When to Use Custom Variables

✅ Good Use Cases

Scenario
Reason

Data Transformation

Convert/format data between steps

State Management

Track values through workflow

Configuration

Centralize settings and parameters

Computed Values

Calculate derived data

Reusable Data

Share across multiple steps

Conditional Logic

Use values in conditions

Output Generation

Compose final results

❌ Anti-Patterns (Don't Do)

  • ❌ Store sensitive data (use Secrets instead)

  • ❌ Use as temporary scratch (defeats purpose)

  • ❌ Overly complex transformations (use helper steps)

  • ❌ Mutable shared state (causes race conditions)

  • ❌ Unclear naming (makes code unreadable)


Variable Scopes

Global Scope

Available across all workflows and executions:

When to use:

  • Project-level constants

  • Shared configuration

  • Frequently changing values

  • Environment settings

Workflow Scope

Available throughout a single workflow execution:

When to use:

  • IDs from API responses

  • Temporary calculations

  • Workflow-specific settings

  • Run-time state

Step Scope

Local to individual step:

When to use:

  • Step-specific processing

  • Temporary values

  • Step outputs

  • Error handling


Variable Types

Primitive Types

Basic data types:

Complex Types

Structured data:


Creating and Using Variables

Creating Variables

Modifying Variables

Accessing Nested Values


Practical Examples

Example 1: Processing User Registration

Example 2: Data Aggregation

Example 3: Multi-Step Data Transformation

Example 4: Configuration Management

Example 5: State Tracking


Variable Operations

String Operations

Numeric Operations

Array Operations

Object Operations


Best Practices

✅ Do

  • Use clear names - user_email not ue or temp

  • Choose right scope - Global for constants, workflow for runtime

  • Document complex variables - Add comments for non-obvious data

  • Initialize before use - Set defaults to avoid null errors

  • Keep simple - Don't over-nest structures

  • Use type checking - Validate before use

  • Clean up - Delete no-longer-needed variables

  • Name by purpose - Reflect what data represents

❌ Don't

  • Use global for temporary - Workflow scope for short-lived data

  • Store secrets - Use proper secret management

  • Over-nest - More than 3 levels gets confusing

  • Reuse for different purposes - Create new variables instead

  • Skip validation - Check null and type before use

  • Use single letters - x, temp, data are unclear

  • Mutate shared state - Can cause race conditions

  • Store large objects unnecessarily - Memory impact


Variable Naming Conventions


Troubleshooting

Issue: Variable is undefined/null

Symptoms:

  • Getting null reference error

  • Variable not found

Causes:

  • Variable not initialized

  • Scope mismatch

  • Conditional logic skipped initialization

Solutions:

  1. Initialize variables before use

  2. Check scope (global vs workflow)

  3. Add null checks

  4. Set default values

Issue: Variable type mismatch

Symptoms:

  • Cannot convert string to number

  • Type error when using variable

Causes:

  • Expected different type

  • API response format changed

  • Missing type conversion

Solutions:

  1. Convert explicitly: parseInt(), toString()

  2. Check API response structure

  3. Add type validation

Issue: Performance degradation

Symptoms:

  • Workflow slowing down

  • Memory usage increasing

Causes:

  • Large variables accumulating

  • Global scope pollution

  • Inefficient data structures

Solutions:

  1. Use appropriate scope (not global for temporary)

  2. Clean up large variables

  3. Use more efficient data structures

  4. Consider moving to Data Hub for large data


Variable Lifecycle

Creation

Usage

Modification

Scope End


Real-World Scenarios

E-Commerce: Order Processing

API Testing: Response Processing



Summary

  • Custom Variables manage data throughout workflows

  • Use different scopes - Global, workflow, or step

  • Choose clear names - Reflect purpose, not role

  • Initialize before use - Prevent null errors

  • Keep simple - Complex nesting reduces readability

  • Validate types - Check before using variables


Next: Learn about Error Handling for robust workflows.

Last updated