Piping is used to customize the survey experience for a particular respondent by inserting a previous question's or variable's response into a subsequent question or location. Piping is useful to clarify exactly what the survey is asking. Piping can be done by any question type that IntelliSurvey offers, but certain question type responses are piped in different ways.
Tip! For more information about piping, see get_answer.
Question or variable references
The syntax for referencing data changes depending on the type of question or variable storing the data. Open-ended questions are referenced by their variable name. Closed-ended questions are referenced by their variable name to pipe the response option ID or option text value, depending on which you're wanting to reference.
Regardless of question type, question variables are recorded in the system with a prefixed capital 'Q'. In the example below, the IntelliSurvey system stores these variables as Q1 and Q2.
1. Where do you live? type: text 2. Do you like it there? type: radio 1. Yes 2. No
Open-ended piping
Open-ended questions (e.g., text, textbox) result in a single response that is typed in. In order to reference the variable for piping of an open-ended question, you would reference the question ID, Q1. In order to pipe the response from Q1, you would need to reference the variable and precede it with a dollar sign ($) – e.g., '$Q1' .
Starting in r8.0, text for both open-end and closed-end responses can be referenced by using $QX_text
. As such the above example can instead use $Q1_text
to reference the text response. SPs are encouraged to use the same option text and option ID referencing across both open-end and closed-end responses.
Closed-ended piping
Closed-ended questions and variables, such as radio, checkbox, pulldown, and rank variables, are made up of question text and options, and the options are made up of an option ID and option text. When a closed-ended question is answered, the system records both the option ID and option text of the response. For piping purposes, SPs can reference both of these pieces later in the survey.
To reference the option text of the question response, you would reference the '_text' variable: the question ID with '_text' added to the end, e.g., $Q3_text
. The '_text' variable is a special variable in the IntelliSurvey system that collects and stores the option text of the selected response(s).
To reference the option ID of the question response, simply reference the question variable itself, e.g., $Q3
.
Radio and pulldown (single-select) piping
Radio and pulldown question types only allow a single selection from the list of options. In the following example, to pipe in the store selected at Q3, the '$Q3_text' variable is inserted into the question text of Q4. This is mainly to customize the experience and serves to remind the respondent which store the survey is talking about.
Option ID piping
To instead pipe the option ID of a closed-end question, drop the '_text' postfix of the variable reference.
Checkbox and listbox (multi-select) piping
Multi-select questions are piped in a similar way as single-select ones. These questions are array references, which means they store multiple values in a single variable, even if the respondent chose only one response. When a multi-select question is referenced via $QX_text
syntax, the system automatically employs the get_answer
helper method.
Autoother piping
Q8 below is a radio question, but one of its options includes an inline text input using autoother. If the respondent's answer was 'Other', then $Q8_text
in the next question would pipe in the text they entered for their answer rather than the word "Other."
The actual text written into the 'Other' option can also be referred to as $Q8_97_OTH
, in which case it pipes like a text question. In r8.0 and beyond, SPs can optionally include '_text' to the autoother variable (e.g., $Q8_97_OTH_text
). We might use this if we wanted to refer to the specific item that they wrote in later - for example, by adding it to a list.
Autoother tip! The way you refer to the variable generated by autoother can be hard to remember. If you're ever in any doubt, it's good practice to upload your question and then look at the reports to see how the system names the 'other' variable.
Piping in blocks
To ask the same format of follow up question about every store selected at Q3A, you could use a block. The following example illustrates one way to pipe in selected options' text from the STORELIST list used at Q3A. To denote the option text of the selected option, you use the %%TEXT%%
placeholder and the system will pipe in the text for that option. Note that the placeholder is not case-specific, so %%text%%
is also allowed.
Piping in loops
Loops are similar to blocks and can be used for iterating (or "looping") a question or group of questions. They operate on the same premise as blocks, but with a simpler syntax, using ~text~
(or ~TEXT~
) to indicate the text placeholder. For example:
Note that option IDs can also be piped in a loop by using either ~id~
(or ~ID~
), and option data decorators can be used in a similar manner.
Piping with Perl [* *]
If you find that get_answer
will not work for your needs, you may pipe text using the method below, but beware of the pitfalls and complexities of using Perl associated with retrieving data from an array.
Putting a piece of code within brackets [* *]
protects your code from any text or characters around the variable.
For example, suppose a client wants to pluralize the piped response. SPs would be allowed to upload the following, but they would receive a syntax error message on the rendered page in their browsers.
Incorrect
How many $Q3_texts are there in your area?
The system doesn't realize that they want the 's' to be at the end of the text to which the code is referring. SPs can clarify that point by "protecting" the code using code block brackets.
How many [* $Q3_text *]s are there in your area?
The above would render as something like the following:
How many Krogers are there in your area?
SPs can think of the way the brackets "protect" their code in two ways:
- The brackets add a physical buffer around your code. Those brackets are sort of a "personal space" for the code that ends right at the edges. That plural 's' above is placed directly next to the brackets, so it looks like it is at the end of 'Kroger' even though it's prevented from being right at the end of '_text.'
-
The brackets tell the code to "calculate this bit first." When the survey reads the variable within the code block brackets, before displaying the surrounding text, it will decode
$Q3_text
to mean 'Kroger', and then render all the text around it – including the plural 's'.
Warning! If programming in IntelliBuilder, do not use the Perl wrapper ([* *]) in question text as it will show as [logic statement] in the platform instead of $Q3_text. Just be cautious of the above issues.
Using Perl with checkbox question piping
In the single-select example above, Q3 is a radio question, so the response options are either 'Safeway' OR 'Kroger' OR 'Trader Joe's' OR 'Whole Foods'. Whichever store the respondent chose would be the single response, and could be piped in. However, if we changed Q3 to a checkbox question, there is a yes or no ('1' or '0', respectively) response associated with each of the store options, and all of that data comprises the response to Q3. The response options become 'Safeway' (yes or no) AND 'Kroger' (yes or no) AND 'Trader Joe's' (yes or no) AND 'Whole Foods' (yes or no).
To reference the items in a multi-select question, or array, you need to reference their index position. An array of selected options is a zero-based index, meaning that the first item is denoted as '0', the second item is denoted as '1', and so on until the end of the list of items in the array. The array only contains the options that were selected in the question.
If you wanted to pipe in the first checked response, you would do so using the following Perl technique to access the "0th" element of the list of answers.
If you only want to remind the respondent of multiple previous answers, you can use a Perl join
or similar function.
You said you shop at [* join(' and ', @$Q3A_text) *].
The above code uses the Perl join
to join together the text ' and ' with the items that were selected at Q3A, which will display as something like the following.
You said you shop at Safeway and Kroger.
Piping the number of checked options
Once one grasps the use of the brackets, it opens up new possibilities for piping. For example, refer back to the Q6 example above, where we ask which brands the respondent has ever used as a checkbox question. If we can protect some code right in the middle of a sentence using brackets, then we could create a follow up to that question that says something like this:
You said you use [* countChecked($Q6) *] brand(s).
The above code block would be displayed as follows:
You said you use 2 brand(s).
Comments
0 comments
Please sign in to leave a comment.