Share feedback, ideas and get community help

Updated last year

How to set multiple variables in one go?

At a glance

A community member asks if it's possible to set multiple variables at once using the 'Set Variable' or 'Script' blocks in Voiceflow. Currently, this functionality is not directly possible.

A workaround was suggested by a community member: store multiple values in an array within a Script Block (e.g., return [sum, product]), and then use separate Set Variable blocks to assign each array value to the desired variables. However, this workaround still requires creating individual Set Variable blocks for each variable, and users must keep track of array indices. JSON key-value pairs were mentioned as an alternative to array indices.

Using the 'Set Variable' or the 'Script' blocks, how can i set multiple variables, in one go.

Example, i a Set Variable block:
Plain Text
const a=1;
const b=2;

{{sum}} = a + b;
{{product}} = a * b;

return true;

Is it possible to set multiple variables, sum and product in this way?

If not, what's a workaround for now?
L
A
S
5 comments
I´d like to do it as well. But I think it´s not possible for now.
Yup, it is not possible right now but I did have a talk with Baptiste that voiceflow allows you to set multiple variable in Script Block..

Workaround: Save all the variable values as an array example:
Plain Text
const a=1;
const b=2;

let sum = a + b;
let product = a * b;

return [sum, product];


and then create 2 more Set Variable block as assign the value from array to you {{sum}} and {{product}} variable..

issue with this workaround?
  • must remember the index for each variable (you can use json key and value i guess too)
  • n*1 blocks for the amount of variables you need to set 😅
@Abdullah Awesome
This still necessitates creating a Set Variable block for each and every variable that needs to be set.
yes hence called the workaround 😅
Add a reply
Sign up and join the conversation on Discord