Menu

Expand
Rate this page:

Set Variables

Set Variables Widget

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 the whitespace generated by the template.

{%- 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 {{flow.variables.<key>}}.

Notes:

  • Variable names are case sensitive. Foo is a different variable than foo.
  • The same key may be set in different widgets. This allows you to update a value.
  • The key itself cannot be a Liquid variable

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).

Screen Shot 2018-12-11 at 10.11.23 AM.png

Rate this page:

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.

        
        
        

        Thank you for your feedback!

        We are always striving to improve our documentation quality, and your feedback is valuable to us. How could this documentation serve you better?

        Sending your feedback...
        🎉 Thank you for your feedback!
        Something went wrong. Please try again.

        Thanks for your feedback!

        Refer us and get $10 in 3 simple steps!

        Step 1

        Get link

        Get a free personal referral link here

        Step 2

        Give $10

        Your user signs up and upgrade using link

        Step 3

        Get $10

        1,250 free SMSes
        OR 1,000 free voice mins
        OR 12,000 chats
        OR more