
- Create counters in loops
- Store calculated values
- Build text from multiple sources
- Save API responses
- Track totals across iterations
- Set default values
set_variable
What This Does (The Simple Version)
Think of this like creating a sticky note during your workflow. You can write down a value and give it a name - then use that name in later actions. It’s useful for calculations, counters, or storing data you’ll need again. Real-world example: You’re looping through 50 deals and want to count how many are high-value. Create a counter variable set to0
, then inside the loop, increase it by 1 each time you find a high-value deal. After the loop, you know exactly how many there are.
How It Works
The Set Variable action creates or updates a variable. You specify:- Variable name - What to call it
- Value - What to store (text, number, or data from other variables)
Setting It Up
Step 1: Add Set Variable Action
Add the Set Variable action to your workflow.Step 2: Name Your Variable
In the “Variable Name” field, type a name for your variable. Good names:deal_count
total_amount
high_priority_deals
enrichment_result
calculated_score
- Use lowercase letters, numbers, underscores
- No spaces or special characters
- Make it descriptive
Step 3: Set the Value
In the “Value” field, enter what you want to store. Three ways to set values: Option 1: Type directly- Type text or numbers directly
- Example:
0
(for a counter) - Example:
High Priority
(for a status)
- Hover to see
{}
button - Click to select variable from previous action
- Example: Click
{}
→deal_record
→properties
→amount
- Mix typed text with variables
- Example: Type “Total: $” then click
{}
→ selecttotal_amount
- Result: “Total: $50000”
Common Patterns
Create a Counter
Goal: Count items in a loop Setup:-
Before loop - Set Variable
- Variable Name:
counter
- Value:
0
- Variable Name:
-
Inside loop - Set Variable
- Variable Name:
counter
- Value: Click
{}
→counter
, then type+ 1
(AI evaluates math)
- Variable Name:
counter
contains total count
Calculate a Total
Goal: Add up deal amounts Setup:-
Before loop - Set Variable
- Variable Name:
total_amount
- Value:
0
- Variable Name:
-
Inside loop - Set Variable
- Variable Name:
total_amount
- Value: {{total_amount}} + {{current_deal.properties.amount}}
- Variable Name:
total_amount
is the sum
Store a Calculation
Goal: Calculate a percentage Setup:- Set Variable
- Variable Name:
win_rate
- Value: {{won_deals}} / {{total_deals}} * 100
- Variable Name:
win_rate
contains the percentage
Build Text from Multiple Parts
Goal: Create a summary message Setup:- Set Variable
- Variable Name:
summary
- Value: Type “Deal ” then click
{}
→deal_name
, type ” worth $” then click{}
→deal_amount
, type ” closed on ” then click{}
→close_date
- Variable Name:
summary
= “Deal Acme Corp worth $50000 closed on 2025-01-15”
Set a Default Value
Goal: Provide fallback if data is missing Setup:- Set Variable
- Variable Name:
contact_name
- Value: {{contact.properties.firstname}} {{contact.properties.lastname}} or if empty
Unknown Contact
- Variable Name:
contact_name
has name or “Unknown Contact”
Common Workflows
Count High-Value Deals
Goal: Count how many deals exceed threshold-
Set Variable (before loop)
- Variable Name:
high_value_count
- Value:
0
- Variable Name:
-
Search HubSpot (V2)
- Find all deals
- Output Variable:
all_deals
-
For Loop
- Loop through:
all_deals
- Current item:
current_deal
- Loop through:
-
If Condition (inside loop)
- Condition: {{current_deal.properties.amount}} > 50000
-
Set Variable (inside if block)
- Variable Name:
high_value_count
- Value: {{high_value_count}} + 1
- Variable Name:
- End Condition
- End Loop
high_value_count
contains the total
Build a Report Summary
Goal: Create text summary from multiple sources-
Search HubSpot (V2)
- Find deals
- Output Variable:
deals
-
Get Timeline Events
- Get activity
- Output Variable:
events
-
Set Variable
- Variable Name:
report
- Value: “Found {{deals}} deals with {{events}} total activities”
- Variable Name:
-
Send Email
- Body: Click
{}
→ selectreport
- Body: Click
Track Running Total
Goal: Sum deal amounts across multiple stages-
Set Variable
- Variable Name:
total_pipeline
- Value:
0
- Variable Name:
- For Loop through deals
-
Set Variable (inside loop)
- Variable Name:
total_pipeline
- Value: {{total_pipeline}} + {{current_deal.properties.amount}}
- Variable Name:
- End Loop
-
Update HubSpot Object
- Update custom property with
total_pipeline
- Update custom property with
Real Examples
Deal Stage Counter
Scenario: Count deals in each stage Before loop:- Set
proposal_count
=0
- Set
negotiation_count
=0
- Set
closed_won_count
=0
- If stage = “proposal” → Increment
proposal_count
- If stage = “negotiation” → Increment
negotiation_count
- If stage = “closedwon” → Increment
closed_won_count
Enrichment Scoring
Scenario: Build a lead score from multiple factors Setup:- Set
score
=0
- If company exists → Set
score
= {{score}} + 10 - If job title contains “VP” → Set
score
= {{score}} + 15 - If email domain is corporate → Set
score
= {{score}} + 5 - If LinkedIn profile found → Set
score
= {{score}} + 10
score
contains total lead score
Troubleshooting
Variable Not Updating
Value stays the same despite Set Variable Possible causes:- Set Variable action not running (inside skipped if block)
- Variable name misspelled
- Value formula incorrect
- Check execution log - did action run?
- Verify exact variable name (case-sensitive)
- Test formula with simple values first
- Check if variable exists before trying to update
Math Not Working
Calculation returns wrong value Possible causes:- Variables are text, not numbers
- Formula syntax incorrect
- Empty/null values in calculation
- AI evaluates math - write it naturally:
5 + 3
or {{count}} + 1 - Check execution log for actual values
- Handle empty values: use If Condition to check first
- Convert text to numbers if needed
Variable Not Available Later
Can’t select variable in later action Possible causes:- Variable created inside loop (only exists inside loop)
- Variable created inside if block (only exists in that block)
- Set Variable action failed
- Create variable BEFORE loop/if block if you need it after
- Check execution log - did Set Variable succeed?
- Variables created inside loops/if blocks have limited scope
Wrong Variable Used
Selected wrong variable from picker Possible causes:- Similar variable names
- Variable from different loop iteration
- Use descriptive names:
deal_count
notcount
- Check variable picker shows correct source
- Review execution log to verify values
Tips & Best Practices
✅ Do:- Use descriptive variable names (
high_value_count
notx
) - Initialize counters to
0
before loops - Initialize totals to
0
before calculations - Use Set Variable for values you’ll reference multiple times
- Create variables outside loops if you need them after
- Check execution log to verify values
- Use variable names that are too similar (
count1
,count2
) - Forget to initialize counters (leads to errors)
- Try to use variables before creating them
- Assume variables from loops persist after loop
- Overcomplicate formulas (break into multiple Set Variable actions)
- Set Variable is instant (less than 0.1 seconds)
- No limit on number of variables
- Variables are lightweight (don’t impact performance)
- Counters:
item_count
,total_deals
,high_priority_count
- Totals:
total_amount
,sum_value
,pipeline_total
- Calculations:
win_rate
,average_score
,conversion_rate
- Text:
summary
,message
,report_text
- Status:
processing_status
,result_code
Last Updated: 2025-10-01