Using folders in script

Created: - Updated:

A folder groups a set of questions inside a survey.

<folder>

Attributes

Attribute

Description

id

Generated by the system; you do not need to set this explicitly

name

Folder name

alias

Alias for this folder

order

Question order (see below)

pipe_from

Reference to a multiple-choice question to pipe values from. The loop will run once for every choice selected.

loop

Loop a specific number of times. Variables can be used e.g. loop="myvar".

max_loop

Defines how many times the columns should be repeated in the reports.

Using folder for loops

Folders are also important for implementing loops. To loop a set of questions, you must place them inside a folder. For example:

Below is the XML script of the above example:

Survey element:

<survey wave="1" order="fixed" status="live" name="Loop test" description="loop" type="diary" track_gps="false" id="581" start_publish="" stop_publish="">
<item id="1"/>
  <folder id="1" name="comic_loop" alias="F1" order="randomized" pipe_from="#1">
    <item id="2"/>
  </folder>
</survey>

Question elements:

Q1

<question type="multi" max_select="-1" min_select="0" order="fixed" id="1" text="Which are your favorite comics? (Choose as many as you want)." alias="Q1">
  <choice id="1" label="Donald Duck Magazines" anchored="false" exclusive="false" alias=""/>
  <choice id="2" label="Donald Duck Pocket Books" anchored="false" exclusive="false" alias=""/>
  <choice id="3" label="Tintin Albums" anchored="false" exclusive="false" alias=""/>
  <choice id="4" label="Asterix Albums" anchored="false" exclusive="false" alias=""/>
  <choice id="5" label="Lucky Luke Albums" anchored="false" exclusive="false" alias=""/>
  <choice id="6" label="Super Hero Comics" anchored="false" exclusive="false" alias=""/>
  <choice id="7" label="Manga Comics" anchored="false" exclusive="false" alias=""/>
</question>

Inside the Folder:

Q2  

<question type="single" max_select="1" order="fixed" id="2" text="How often do you buy $answer(Q1) ?" alias="Q2">
  <choice id="1" label="Every Day" anchored="false" exclusive="false" alias=""/>
  <choice id="2" label="1-2 times a week" anchored="false" exclusive="false" alias=""/>
  <choice id="3" label="1-2 times per month" anchored="false" exclusive="false" alias=""/>
  <choice id="4" label="More seldom than once a month" anchored="false" exclusive="false" alias=""/>
</question>

Please refer to text piping to learn more about ($answer(Q1) used in the above example.

Scenario

Q1 Respondent chooses choice 3, 4 and 5. The loop will run once for every choice selected.

Q2 Question text will show "How often do you buy Tintin Albums?"

Loop back to Q2

Q2 Question text will show "How often do you buy Asterix Albums?"

Loop back to Q2

Q2 Question text will show "How often do you buy Lucky Luke Albums?"