Use the import data
widget to name a variable, and then assign a value to it. It's used for defining and populating variables used only for survey logic and is not stored in the survey data set.
import data
is useful when survey logic relies on external data, like spreadsheets, without embedding that data in the survey code.
Example
Suppose you need to display a list of price ranges based on previous responses. The price ranges are stored in an external sheet (priceranges.xlsx).
Follow these steps to use import data
in this scenario.
-
Ask a respondent about their spending.
1. Please select the smallest amount you've spent on this product: type: radio 0. $0 1. $1 2. $2 3. $3 4. $4 5. $5 6. $6 7. $7 8. $8 9. $9 1A. Please select the largest amount you've spent on this product: type: radio 1. $1 2. $2 3. $3 4. $4 5. $5 6. $6 7. $7 8. $8 9. $9
-
Define a variable to store the combined response. For example, if the respondent answered $0 for Q1 and $4 for Q1A, the value stored at QRESP would be '104'.
RESP. Respondent Type type: text invisible: y cvalue: {"1" . $Q1 . $Q1A}
-
Use
import data
to name the variable 'rangetext' and fetch the relevant price ranges in the 'priceranges' sheet. Continuing with the example above, the row value would be the same as QRESP, which is '104'.Note, if there is already a page break between step 2 and step 3 in your survey code, the
new page
tag can be removed.new page
import data: (rangetext => fetch_row(name => 'priceranges', row => $QRESP)) -
Display the fetched ranges in an HTML list. For example, in row 104, the values that would be pulled in would be, '022-031', '032-041', 042-0551', and so on.
<ul> <li>$[* $rangetext->{range1} *]</li> <li>$[* $rangetext->{range2} *]</li>
<li>$[* $rangetext->{range3} *]</li> ...etc. </ul>
Details
- The value assigned may be a hash or a hashref, and as such accepts
fetch_cell
andfetch_row
. - A basic syntax example to follow with
fetch_row
is:import data: ( variablename => fetch_row( name => 'sheetname', row => row id ) )
- A basic syntax example to follow with
fetch_cell
, is:import data: ( variablename => fetch_cell( name => 'sheetname', row => row id, column => col id ) )
- Multiple variables may be defined.
- Use the
prefix
tag to add a prefix to all variable names with a given string.
Comments
0 comments
Please sign in to leave a comment.