We have 3 different options when using the Global Vars:
1. GlobalVars - Holds any information, according to the logic you implement, on the device level which means you can use it at any of the interviews running on the device no matter what survey they are from.
2. SurveyGlobalVars - Holds any information, according to the logic you implement, on the specific survey level that it was defined for and use it across interviews that are of that specific survey on that device.
3. Vars - Hold data in a global variable which will be available to fetch from every single place in your survey – Global variables are the answer.
Global Variables are used to store different data, making it available through all of your survey.
This how to will instruct on how to create global variables and how to use them.
How Global Variables Are Constructed?
Global variable need to have to parameters:
1. The Key (the name of the variable).
2.The Value (Can be a number, a text input or a Boolean value)
‘Vars’ is basically declaring that this is a global variable.
Please note: where in the example you see 'Vars' you can also use either 'GlobalVars' or 'SurveyGlobalVars'
Where To Create A Global Variable?
In any place you want across your survey (start & end scripts\advanced scripts\ survey init code) you can declare
How To Create A Global Variable?
Here are real examples of how you can create global variables:
As you can see, we have declared the ‘Vars’ component in order to make the system ‘know’ it is global.
We used the square bracelets, and placed the key name within.
Then we set a value to our keys.
How To Access A Global Variable?
In any place in your survey which you need to have any use of one of your global variables, you can just write it with its name, for example:
Like this you can use the value they hold in rules,scripts,etc’.
// DO SOME NICE CODE
If you wish to change a global variable value, just add the ‘=’ operator and write the new value, for example: