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¶
- Add Variable task
- Set variable name
- Set variable value
- Access later:
{{task_41001_value}} - Save
Simple Example:
Configuration¶
Set Variable¶
Store calculation result:
Store text:
Store dynamic data:
Store 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:
Use in If condition:
Use in Email:
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:
Access after loop:
Flag Storage¶
Set flag based on condition:
// Code task
const isHighValue = parseFloat(input.task_43001_total) > 10000;
return { high_value_flag: isHighValue };
Store flag:
Use in If task:
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:
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:
If Task 1:
If Task 2:
If Task 3:
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:
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:
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:
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:
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¶
- Descriptive names -
email_sent_countnotcount - Context-specific -
loop_success_totalnottotal - Consistent format - All snake_case or all camelCase
- 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¶
- Don't overuse - Only store what you need later
- Keep values small - Large JSON can slow workflow
- Clean data - Store processed, not raw data
- Use direct references - If task output available, use it directly
Data Types¶
Store appropriate format:
Numbers:
Text:
Boolean:
JSON:
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:
Can't Access in Loop¶
Issue: Variable set outside loop, not updating inside
Solution: Update variable inside loop:
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:
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:
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:
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('')
};
Related Tasks¶
- 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