Question variable

In AskiaScript, a question variable is a question within the survey structure. The name of the variable is the question shortcut. See question type definition for more information.

The question variable is on the global scope, which means you can use it anywhere in your survey, even if the question has not been asked (e.g. it was skipped in this particular interview).

This kind of variable is state-full, which means that if you stop the current interview and go back to it later, the value of the variable is still there.

To access the question variable, you can use the shortcut of the question, using one of the following syntaxes:

Syntax Description
??shortcut??

This syntax returns the value(s) (answers) of the question:

  • A number for a numeric and single closed question

  • A string for an open-ended question

  • An array of numbers for a multi-coded question

  • A date for a date question

Examples:

??gender??  ' => 1 for Male

??age??     ' => 35

??brands??  ' => {3; 5; 7}
%%shorcut%%

This syntax returns the entry code(s) (answers) of the closed question:

Examples:

%%country%%   ' => 4

%%brands%%    ' => {4; 7; 1}
shortcut

This syntax returns a question object.

This syntax is available if the shortcut:

  • begins with a letter or underscore

  • contains only alphanumeric characters and underscores (_).

  • does not contain any spaces

  • is not a reserved keyword

If one of the above conditions is not reached, it is always possible to use the long form syntax by encapsulating the shortcut between hat characters (^):
^shortcut with irregular form^

Examples:

q1

gender

gender_of_respondent

^1. gender of respondent^

 

Create your own Knowledge Base