The allowreadsfrom
tag is used with get_answer
to either access a survey data set from a different survey or other respondents' answers within the same survey. This is particularly useful when respondents are re-contacted for a second survey.
Single select data pull from another survey
Main survey (is01152025)
appconfig
allowreadsfrom: is01152025rc
5. Which is your favorite fast food restaurant?
type: radio
1. McDonald's
2. Starbucks
3. Subway
4. KFC
5. Domino's
6. Burger King
7. Pizza Hut
Recontact survey (is01152025rc)
5RC. Please read the list of restaurants provided below and select your favorite one again.
preface: The restaurant you previously stated as your favorite is selected below.
type: radio
dvalue: get_answer('Q5', appid => 'is01152025')
1. McDonald's
2. Starbucks
3. Subway
4. KFC
5. Domino's
6. Burger King
7. Pizza Hut
8. Dunkin' Donuts
9. Taco Bell
Using get_answer
and allowreadsfrom
, you can dynamically access respondents' answers from the main survey and display them as default answers in the a recontact survey. In the example below, the allowreadsfrom
tag is added to the appconfig
widget in the main survey and lists the recontact survey's ID as the input. Then, Q5RC in the recontact survey uses the dvalue
tag to pre-select the option ID pulled in from the main survey via get_answer
. New options are also provided, and the respondent is asked to re-answer the question.
This works as long as the respondent ID is the same in both surveys.
Details
- Include
allowreadsfrom
in theapp config
widget in the main survey where the data is hosted. - Specify the survey ID(s) permitted to access and pull the data in a comma-separated list.
- The
allowreadsfrom
tag is required in theapp config
widget when referencing data from a different respondent record, even within the same survey. - To pull data for a specific question, from a different respondent in the same survey, use
get_answer('QuestionID', trans_id => 'respondentID' )
. - To pull data for a specific question in a different survey than where the data is hosted, for a respondent that has a different ID in each survey, use
get_answer('QuestionID', trans_id => 'respondentID', appid => 'SurveyID' )
. - The
trans_id
parameter can be omitted if the data being requested uses the same respondent ID in both surveys, for exampleget_answer('QuestionID', appid => 'SurveyID' )
. If thetrans_id
parameter is omitted, the current respondent ID is used by default. - For data pulls involving tables, a unique
get_answer
statement must be created for each individual table field (e.g., row). -
To reference variables in
get_answer
parameters, use double quotes to ensure proper interpolation.
Note: The allowreadsfrom
tag will have an immediate effect once loaded into the survey source code. If the survey is live, but the source code is a "Draft," the allowsreadsfrom
will be actively functioning. Alternatively, if you remove allowsreadsfrom
in the most recent source code, published or not, it will no longer function.
Additional examples
Multiselect data pull from another survey
The example below is set up the same way as the previous one. However, the data is being pulled from a multiselect (checkbox) question. In Q6RC, use the split
function in the cvalue
tag to store the data correctly.
This works as long as the respondent ID is the same in both surveys.
Note that in this example, we are not re-asking the question; instead, we are storing the data in a coded variable so that it can be referenced for logic later in the new survey. The invisible
tag has been added to Q6RC to achieve this.
Main survey (is01152025)
appconfig
allowreadsfrom: is01152025rc
6. What pets have you ever had?
type: checkbox
1. dog
2. cat
3. bird
4. rat
5. gerbil
6. hamster
7. hedgehog
8. fish
9. iguana
10. bearded dragon
11. turtle
Recontact survey (is01152025rc)
6RC. What pets have you ever had?
type: coded multiple select
selectby: calculate
cvalue: [split(', ', get_answer('Q6', appid => 'is01152025'))]
1. dog
2. cat
3. bird
4. rat
5. gerbil
6. hamster
7. hedgehog
8. fish
9. iguana
10. bearded dragon
11. turtle
Pulling data for tables
For data pulls involving tables, a separate get_answer
statement must be created for each field individually. You can use a block to create the get_answer
statements and set value
to store the data to the table's fields, as shown in the example below.
This works as long as the respondent ID is the same in both surveys.
Main survey (is01152025)
appconfig allowreadsfrom: is01152025rc
2. What is your favorite time of day for each of these activities?
type: radio table
1. Morning
2. Afternoon
3. Evening
rows:
1. Exercising
2. Reading
3. Watching TV
Recontact survey (is01152025rc)
2. What is your favorite time of day for each of these activities? type: radio table invisible: y 1. Morning 2. Afternoon 3. Evening rows: 1. Exercising 2. Reading 3. Watching TV block: <<ENDQ2 setvalue question: Q2R%%ID%% value: get_answer('Q2R%%ID%%', appid => 'is01152025' ) condition: 1 ENDQ2 list: T2.rows
Referencing variables in parameter values
Continuing with the example of having a main survey and a recontact survey, imagine the respondent ID is not the same. In this case, you can create a variable in the recontact survey to link the respondent ID from the main survey to the respondent ID in the recontact survey.
Assume the trans_id
from the main survey is appended as a custom parameter in the survey invite link, for example 'oid', and stored in a variable called QORIGINAL in the recontact survey. The trans_id
parameter is then used with get_answer
to specify and retrieve the corresponding value.
Next, variable QVAR1 collects the answers from Q1 from the main survey, is01152025, and specifically references the text stored at QORIGINAL as the trans_id
value. For example, if trans_id
"1234" was stored at QORIGINAL, the get_answer
code will use trans_id => 1234
for that respective respondent. Reminder, the QORIGINAL variable is enclosed in double quotes to ensure proper interpolation with get_answer
.
ORIGINAL. Original ID
type: text
invisible: y
cvalue: if (url_param('oid') ne "") {url_param('oid')} else {$trans_id}
VAR1. Variable 1
type: radio
invisible: y
cvalue: get_answer('Q1', trans_id => "$QORIGINAL", appid => 'is01152025')
1. blue
2. red
3. orange
4. yellow
5. green
6. purple
Comments
0 comments
Please sign in to leave a comment.