Response array (favorites)

Created: - Updated:

This article covers these topics:

Introduction to response arrays

Response arrays are used to store answers to any number of questions in one single variable. The most common use of a response array is to script favourites, a diary functionality where respondents can complete an entry by simply "playing back" a previously stored entry.


The available functions for response arrays are described below:


recordanswers(var, [start_question],[end_question])

Saves the answer(s) from the start question to the end question into the entry.


  • recordanswers(var): Saves all answers currently set in the survey in the variable var (including local variables).
  • recordanswers(var, Q1): Saves the answer of the specified question in the variable var. If var already contains Q1 answers those are replaced, otherwise appended.
  • recordanswers(var, Q1, Q5): Saves all answers in the range specified, including Q1 and Q5, in variable var. If var already contains answer from Q1 to Q5 those are replaced, otherwise appended.

Note 1: It only saves questions that actually have an answer, so if you run this function on the first question in the survey it will only record the first question, since no other answers have been set in the survey.

Note 2: both Alias and question ID can be used to reference start_question and end_question.

playanswers(var) Loads entry saved in the specified variable and runs setanswer() on all the answers found in the entry.

Deletes the answer from the saved entry.

  • deleteanswers(var) - Deletes the whole record.

  • deleteanswers(var, Q1) - Deletes the answer of the specified question from an old record if available.

Note: both Alias and question ID can be used to reference the question.


You can find an example of this functionality in the survey !link attached; import the survey and run through it. You will notice in Q1, the first day of this diary, the respondent can answer all question for each meal, which then will change that meal choice from "Meal" to "My usual Meal" which will run the "playanswers" function and skip the recorded questions.

<question type="single" max_select="1" order="fixed" style="more-options-below" enable_lookup="false" optional_response="false" id="1" text="Which meal is this?" alias="Q1">

  <postcondition if="answer(Q1)==7" then="goto(Q6)"/>

  <postcondition if="answer(Q1)==2 && isglobalset(MyBreakfast)" then="playanswers(MyBreakfast);goto(Q4)"/>

  <postcondition if="answer(Q1)==4 && isglobalset(MyLunch)" then="playanswers(MyLunch);goto(Q4)"/>

  <postcondition if="answer(Q1)==6 && isglobalset(MyDinner)" then="playanswers(MyDinner);goto(Q4)"/>

  <choice id="1" label="Breakfast" anchored="false" exclusive="false" alias="" if="!isglobalset(MyBreakfast)"/>

  <choice id="2" label="My usual Breakfast" anchored="false" exclusive="false" alias="" if="isglobalset(MyBreakfast)"/>

  <choice id="3" label="Lunch" anchored="false" exclusive="false" alias="" if="!isglobalset(MyLunch)"/>

  <choice id="4" label="My usual Lunch" anchored="false" exclusive="false" alias="" if="isglobalset(MyLunch)"/>

  <choice id="5" label="Dinner" anchored="false" exclusive="false" alias="" if="!isglobalset(MyDinner)"/>

  <choice id="6" label="My usual Dinner" anchored="false" exclusive="false" alias="" if="isglobalset(MyDinner)"/>

  <choice id="7" label="Other" anchored="false" exclusive="false" alias=""/>


That worked, because the script has recorded the answers in Q5 (for Q2 -and - Q3):

<question type="slider" max_select="1" optional_response="false" id="5" text="How did you feel after eating your $answer(Q1)?" alias="Q5">

  <precondition if="answer(Q1)==1" then="recordanswers(MyBreakfast,Q2,Q3)"/>

  <precondition if="answer(Q1)==3" then="recordanswers(MyLunch,Q2,Q3)"/>

  <precondition if="answer(Q1)==5" then="recordanswers(MyDinner,Q2,Q3)"/>

  <choice id="1" label="Fine" anchored="false" exclusive="false" alias=""/>

  <choice id="4" label="OK" anchored="false" exclusive="false" alias=""/>

  <choice id="7" label="Heavy" anchored="false" exclusive="false" alias=""/>