The allowreadsfrom
tag is used in concert with the get_answer
method to import data from other respondent records and/or surveys that reside on the same server.
This can be useful in situations where respondents are re-contacted to take a second survey. Survey Programmers (SPs) would first include allowreadsfrom
on the app config
widget of the first survey. Then, using get_answer
, response information from the first survey can be used to manipulate data in the second survey. The allowreadsfrom
tag is required on the appconfig
widget when data is being referenced from a different respondent record, even if it is in the same survey.
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 in "Dev Mode," 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.
Syntax
To enable the accessing of survey data from remote respondent records and/or surveys, the allowreadsfrom
tag is required on the appconfig
widget of the parent survey (the survey from which you are pulling data). This unlocks the functionality of the trans_id
and app_id
parameters. Then, specify the survey which is permitted to access the parent survey's data. Multiple surveys can be specified in a comma separated list.
Note, if cross-record reference is occurring within the same survey, the allowreadsfrom
tag is still required.
appconfig allowreadsfrom: SurveyID,Another_SurveyID # Requesting the data for a specific question, from a different respondent, in the same survey. get_answer('QuestionID', trans_id => 'respondentID' ) # Requesting the data for a specific question in a different survey than where the data is hosted. The trans_id parameter can be omitted if the data being requested uses the same respondentID. get_answer('QuestionID', trans_id => 'respondentID', appid => 'SurveyID' )
Note: The allowreadsfrom
tag must be included in the app config
for the survey that hosts the original data. For the "Remote Data" examples below, readers should assume that allowreadsfrom
has already been included in the survey(s) from which the data originates; get_answer
cannot simply reference the "parent"/hosting survey via app_id
without it.
Examples
Single select data pull from another survey
At times recontact surveys will need to be run, and data that was collected in the original (main) survey will need to be accessed to pull in respondent-specific data (e.g., brands used, ratings, or text) to drive logic in the recontact survey. Through the use of get_answer
and allowsreadsfrom
, this is possible.
In the following example, let's imagine the client realized an answer choice, the color "violet," was left off the list at Q5. It has been requested to re-ask the question, and give respondents the opportunity to change their answer. SPs need to dynamically access all respondents' answers at Q5 in the main survey test_doc and show the response as the default answer selected in the new Q5RC. To accomplish this, the allowsreadsfrom
tag must be added to app config
of test_doc and specifically list the recontact survey's ID test_doc2. Then, in the recontact survey, get_answer
is applied at the dvalue
tag at Q5RC to pipe in the response from Q5 in the main survey and show it as the default response. The respondent then has the opportunity to keep or change their answer.
This works so long as the respondent ID is the same in both surveys.
##Main survey (test_doc) appconfig allowreadsfrom: test_doc2 5. Which is your favorite color? type: radio 1. red 2. orange 3. yellow 4. green 5. blue 6. indigo ##Recontact survey (test_doc2) 5RC. This will show the answer selected at Q5 at test_doc as long as the SAME RESPONDENT ID is used. type: radio dvalue: get_answer('Q5', appid => 'test_doc') 1. red 2. orange 3. yellow 4. green 5. blue 6. indigo 7. violet
Multiple select data pull from another survey
As mentioned in the previous example, sometimes data from a separate survey is needed to drive logic in a new survey, e.g., a recontact survey. If remote data is needed merely for survey logic, it is best practice to not re-ask questions because respondents can contradict themselves, which leads to inconsistent data and poor quality. For example, if an SP needs to know how many brands were previously used by the respondent in order to ask a missed follow up question, the SP should collect the information in a hidden variable and then reference the variable in survey logic.
In the example below, the SP is using the same two surveys as the previous example; allowreadsfrom
has already been added to the appconfig
in the main survey. In the recontact survey, Q6RC is created to receive and store the data. It is a multiple selection question type, but it uses the invisible
tag and is not shown on screen to respondents. The cvalue
tag is used with the Perl split
function to transform the multiple selections in a way that can be correctly stored and used. Note, data from a multiple selection type question using get_answer
cannot be accurately stored without it.
Again, the same respondent ID needs to be used in the recontact survey for this process to work.
##Main survey (test_doc) appconfig allowreadsfrom: test_doc2 6. What pets you have ever had? type: checkbox 1. dog 2. cat 3. bird 4. rat 5. bird 6. gerbil 7. hamster 8. hedgehog 9. fish 10. iguana 11. bearded dragon 12. turtle ##Recontact survey (test_doc2) - This will create a variable in the recontact survey with the responses from Q6 in the main survey. 6RC. Pets selected at Q6 in main survey type: checkbox invisible: y cvalue: [split(', ',get_answer('Q6', appid => 'test_doc'))] 1. dog 2. cat 3. bird 4. rat 5. bird 6. gerbil 7. hamster 8. hedgehog 9. fish 10. iguana 11. bearded dragon 12. turtle
Single select table data pull from another survey
Tables create a set of fields in the survey data. For data pulls involving tables, a separate get_answer
statement must be created for each field individually. SPs can use a block to create the get_answer
statements to match the table's fields, as shown in the example below.
##Main survey (test_doc) appconfig allowreadsfrom: test_doc2 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 (test_doc2) - Create a block of setvalue statements to populate the table. 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 => 'test_doc' ) condition: 1 ENDQ2 list: T2.rows
Referencing variables in parameter values
To reference any variable in get_answer
parameters, use double quotes surrounding its value so it properly interpolates the variable. In basic terminology, double quotes tells the system "$QSHOWTHIS" on screen.
Continuing with the example of having a main survey and a recontact survey, let's imagine the respondent ID is not the same. Some panel companies are not able to use the same respondent ID when a recontact is needed. In this case, it is possible to create a variable in the recontact survey that will link the respondent ID from the main survey to the respondent ID in the recontact survey. The trans_id
from the main survey is appended as a custom parameter in the survey invite link. It is then stored in a variable called QORIGINAL in the recontact survey. Then, the trans_id
parameter is used with get_answer
to specify the value that should be shown, and therefore, used in this syntax.
Next, variable QVAR1 collects the answers from Q1 from the main survey test_doc and specifically references the text stored at QORIGINAL as the trans_id
value. So, if trans_id
"1234" was stored at QORIGINAL, then the get_answer
code will use trans_id => 1234
for that respective respondent.
Reminder, if the trans_id
parameter is omitted, the current respondent ID is used by default.
##This variable would be in the recontact survey. It maps the trans_id from the recontact survey to the trans_id from the main survey. ORIGINAL. Original ID type: text invisible: y chapter: P1 cvalue: if (url_param('oid') ne "") {url_param('oid')} else {$trans_id} ##This variable collects the answers from Q1 from the main survey (test_doc) to be used in the recontact survey. VAR1. Variable 1 type: checkbox invisible: y cvalue: [split(', ',get_answer('Q1', appid => 'test_doc', trans_id => "$QORIGINAL"))] 1. blue 2. red 3. orange 4. yellow 5. green 6. purple ##For a radio variable, the split syntax would not be needed. dvalue: get_answer('Q1', trans_id => "$QORIGINAL", appid => 'test_doc')
Comments
0 comments
Please sign in to leave a comment.