Set Variables
Description:
Set Variables allows you to save key/value pairs in the global context of the flow execution. Variables set via the widget are accessible throughout your flow via other widgets under the key {{flow.variables.<key>}}
. This allows you to enable use cases such as counters that are dynamically updated as your flow executes.
Optional Configuration:
You can add any number of Variables. Variables can have static values like a single number or string, or dynamic values set via the Liquid templating language.
Example that sets a variable called count to 0 if not set and increments it if it exists.
Tip: Be sure to use the hyphen in your Liquid tags to remove extra whitespace generated by the template. Any tag without a hyphen in it creates a blank line; for example, the below code snippet outputs a single line, but without hyphens it would have three blank lines plus the expected output, which would cause the integer to be treated as a string.
{%- if flow.variables.count -%} {{flow.variables.count | plus: 1}} {%- else -%} 0 {%- endif -%}
Configuration
Name |
Description |
Key |
The name of this variable, once set, will be accessible in Liquid via Notes:
|
Value |
The variable value to set. This can be a number or string value, or a Liquid expression like the example above. |
Transitions
There is only one transition from this widget, "Next" which fires once any variables specified are set.
Example Flow
In the call flow screenshot below, the count variable is set to 0 when the flow starts, and the flow will loop until the count variable is equal to 3 and then exit (The set variable widget uses the sample Liquid template code from above).
Need some help?
We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd browsing the Twilio tag on Stack Overflow.