Skip to content

Variable Task

Overview

The Variable Task stores and retrieves data within a workflow execution. Use it for temporary calculations, counters, flags, intermediate results, or passing data between distant tasks.

When to use this task:

  • Store calculated values for later use
  • Count loop iterations or successes
  • Set flags for conditional logic
  • Cache data to avoid repeat queries
  • Accumulate totals across loop
  • Store intermediate processing results
  • Pass data across complex workflows

Key Features:

  • Store any data type (text, numbers, JSON)
  • Persist within workflow execution
  • Access anywhere in workflow
  • Update incrementally
  • Multiple variables per workflow
  • No external dependencies
  • Fast and reliable

Quick Start

  1. Add Variable task
  2. Set variable name
  3. Set variable value
  4. Access later: {{task_41001_value}}
  5. Save

Simple Example:

Variable Name: lead_score
Value: {{task_42001_calculated_score}}

Use later: {{task_41001_value}}

Configuration

Set Variable

Store calculation result:

Variable Name: total_revenue
Value: {{task_43001_sum_revenue}}

Store text:

Variable Name: status
Value: Processed

Store dynamic data:

Variable Name: contact_name
Value: {{task_47001_full_name}}

Store JSON:

Variable Name: contact_data
Value: {{task_43001_results_JSON}}

Variable Naming

Best practices: - Use descriptive names: lead_score not var1 - Snake_case preferred: total_count not totalCount - Be specific: email_sent_count not count

Accessing Variables

After Variable task executes:

Access value:

{{task_41001_value}}

Use in If condition:

If {{task_41001_value}} > 100:
  → High value path

Use in Email:

Subject: Score: {{task_41001_value}}

Use in MySQL:

UPDATE contacts SET score = ? WHERE id = ?
Parameters: {{task_41001_value}}, {{task_47001_contact_id}}

Common Patterns

Counter

Increment in loop:

// Code task in loop
let count = parseInt(input.task_41001_value) || 0;
if (input.task_x_success) {
  count++;
}
return { counter: count };

Store new count:

Variable Name: success_count
Value: {{task_42001_counter}}

Access after loop:

Email: {{task_41001_value}} items processed successfully

Flag Storage

Set flag based on condition:

// Code task
const isHighValue = parseFloat(input.task_43001_total) > 10000;
return { high_value_flag: isHighValue };

Store flag:

Variable Name: is_high_value
Value: {{task_42001_high_value_flag}}

Use in If task:

If {{task_41001_value}} = true:
  → Send to sales manager

Cache Data

Avoid repeat queries:

1. MySQL Query - Get customer data
2. Variable - Store {{task_43001_results_JSON}}
3. Loop - Process items
4. In loop: Access {{task_41001_value}} instead of querying again

Accumulator

Sum values across loop:

// Code task in loop
let total = parseFloat(input.task_41001_value) || 0;
total += parseFloat(input.task_29001_amount) || 0;
return { running_total: total };

Update variable:

Variable Name: total_amount
Value: {{task_42001_running_total}}

Real-World Examples

Example 1: Lead Scoring with Thresholds

Workflow: 1. CRM Trigger - Lead created 2. Code Task - Calculate score 3. Variable - Store score 4. If Task - Check threshold 5a. High score (>80) → Sales manager 5b. Medium score (50-80) → Sales rep 5c. Low score (<50) → Nurture campaign

Calculate score:

const hasPhone = input.task_47001_phone ? 20 : 0;
const hasCompany = input.task_47001_company_name ? 15 : 0;
const hasWebsite = input.task_47001_website ? 15 : 0;
const emailDomain = input.task_47001_email.split('@')[1];
const isBusiness = !['gmail.com','yahoo.com','hotmail.com'].includes(emailDomain) ? 25 : 0;
const hasMessage = input.task_47001_message?.length > 50 ? 25 : 0;

const totalScore = hasPhone + hasCompany + hasWebsite + isBusiness + hasMessage;

return { score: totalScore };

Store score:

Variable Name: lead_score
Value: {{task_42001_score}}

If Task 1:

Condition: {{task_41001_value}} >= 80
True: Email sales manager with hot lead

If Task 2:

Condition: {{task_41001_value}} >= 50 AND {{task_41001_value}} < 80
True: Assign to sales rep

If Task 3:

Condition: {{task_41001_value}} < 50
True: Add to nurture campaign

Example 2: Processing Success Tracker

Workflow: 1. Schedule Trigger - Daily sync 2. MySQL Query - Get records to process 3. Variable - Initialize counters 4. Loop - Process each record 5. Webhook Out - Sync to external API 6. Code Task - Update counters 7. Variable - Store updated counters 8. (After loop) Email - Send summary

Initialize counters:

Variable Name: counters
Value: {"success": 0, "failed": 0, "total": 0}

Update counters (in loop):

const counters = JSON.parse(input.task_41001_value);
counters.total++;

if (input.task_1001_status_code === 200) {
  counters.success++;
} else {
  counters.failed++;
}

return { 
  updated_counters: JSON.stringify(counters),
  success_rate: ((counters.success / counters.total) * 100).toFixed(1)
};

Store updated counters:

Variable Name: counters
Value: {{task_42001_updated_counters}}

Summary email (after loop):

To: admin@company.com
Subject: Daily Sync Complete

Total processed: {{task_42001_total}}
Successful: {{task_42001_success}}
Failed: {{task_42001_failed}}
Success rate: {{task_42001_success_rate}}%

Example 3: Multi-Step Calculation Cache

Workflow: 1. CRM Trigger - Order created 2. MySQL Query - Get customer history 3. Code Task - Calculate LTV 4. Variable - Store LTV 5. Code Task - Determine discount tier 6. Variable - Store tier 7. Email - Confirmation with discount 8. Edit Client - Update customer tier

Calculate LTV:

const orders = JSON.parse(input.task_43001_results_JSON);
const ltv = orders.reduce((sum, order) => sum + parseFloat(order.total), 0);
return { lifetime_value: ltv.toFixed(2) };

Store LTV:

Variable Name: customer_ltv
Value: {{task_42001_lifetime_value}}

Determine tier:

const ltv = parseFloat(input.task_41001_value);
let tier = 'Bronze';
if (ltv >= 10000) tier = 'Platinum';
else if (ltv >= 5000) tier = 'Gold';
else if (ltv >= 1000) tier = 'Silver';

const discount = tier === 'Platinum' ? 20 : tier === 'Gold' ? 15 : tier === 'Silver' ? 10 : 5;

return { 
  customer_tier: tier,
  discount_percent: discount
};

Store tier:

Variable Name: customer_tier
Value: {{task_42001_customer_tier}}

Email:

Hi {{task_47001_first_name}},

Your order is confirmed!

As a valued {{task_41002_value}} customer (LTV: ${{task_41001_value}}),
you receive {{task_42001_discount_percent}}% off your next order!

Update CRM:

Contact ID: {{task_47001_contact_id}}
Update: custom_tier = {{task_41002_value}}
Update: custom_ltv = {{task_41001_value}}

Best Practices

Naming Conventions

  1. Descriptive names - email_sent_count not count
  2. Context-specific - loop_success_total not total
  3. Consistent format - All snake_case or all camelCase
  4. Avoid conflicts - Don't reuse same name for different data

When to Use Variables

Good use cases: - Calculations used multiple times - Counters and accumulators - Flags for conditional logic - Caching expensive queries

Bad use cases: - Data available from previous task (just use that task's output) - Passing data to next immediate task (direct reference better) - Storing large datasets (use database instead)

Performance

  1. Don't overuse - Only store what you need later
  2. Keep values small - Large JSON can slow workflow
  3. Clean data - Store processed, not raw data
  4. Use direct references - If task output available, use it directly

Data Types

Store appropriate format:

Numbers:

Value: 42

Text:

Value: Completed

Boolean:

Value: true

JSON:

Value: {"key": "value"}

Troubleshooting

Variable Empty or Undefined

Check: 1. Variable task executed before access? 2. Correct task ID in reference? 3. Value set in configuration? 4. Previous task output exists?

Debug:

View execution history → Variable task → Check output

Can't Access in Loop

Issue: Variable set outside loop, not updating inside

Solution: Update variable inside loop:

1. Initialize variable (before loop)
2. In loop: Read variable, calculate, update variable

Lost After Loop

Issue: Variable value from loop lost

Cause: Variable holds last iteration value only

Solution: Use accumulator pattern (see Example 2).

Number Stored as Text

Issue: Math operations fail

Solution: Parse in Code task:

const value = parseFloat(input.task_41001_value) || 0;

Frequently Asked Questions

How long does variable data persist?

Duration of single workflow execution. Not saved between runs.

Can I use variables across different workflows?

No. Use database or Edit Client task for persistent storage.

How many variables can I create?

Unlimited, but practical limit ~10-20 per workflow for clarity.

Can I store arrays?

Yes, as JSON:

Value: [1, 2, 3, 4, 5]
Access: {{task_41001_value}}
Parse in Code task: JSON.parse(input.task_41001_value)

Can I update a variable?

Yes, add another Variable task with same name:

Variable Name: counter
Value: {{task_42001_new_count}}
Overwrites previous value.

What's difference between Variable and Edit Client?

  • Variable: Temporary, workflow-only, fast
  • Edit Client: Permanent, saved to CRM, slower

Can I use variables in If conditions?

Yes:

If {{task_41001_value}} > 100
If {{task_41001_value}} = "Completed"

How to access variable in different format?

Use Code task to transform:

const value = input.task_41001_value;
return {
  uppercase: value.toUpperCase(),
  length: value.length,
  reversed: value.split('').reverse().join('')
};


  • Code Task - Calculate values to store
  • If Task - Conditional logic with variables
  • Loop Task - Counters and accumulators
  • Edit Client - Permanent storage alternative
  • MySQL Query - Persistent data storage