Solved
Check user selectIon against a lookup table, write other values in that row to embedded data
TL;DR Create a VLOOKUP equivalent in Qualtrics?
---------------
I have several surveys that are similar, but with various tweaks. There are about 12 surveys now, but that could grow to 30+. Instead of having several different surveys that are all similar, I'd like one survey that is customized based on the user's response to the first question. (The surveys are about sport leagues, so you'll see some of that language in here.)
For example, if the user selects "MLB" on page 1, I'd like to show survey Blocks A, B, and C. But, if the user selects "EPL," the user would see Blocks A, B, and E.
I could build a bunch of if/then logic statements into Qualtrics to accomplish this, but that seems horribly inefficient. It's also more rigid than I'd like, since when I make changes in the future I might want the "EPL" respondents to see Blocks A, D, F, and K.
My idea is to create an embedded field that corresponds with each Block (e.g., "blnShowBlockA", "blnShowBlockB", "blnShowBlock_"). If the Block should be shown to respondents, that field will get flipped to TRUE. Then, in the survey flow, I'll put branch logic before every Block; if the blnShowBlock_ variable associated with that Block is TRUE, Qualtrics will show that Block. But, how do I write each TRUE where it's supposed to be...
My thought is to create a lookup table with Blocks across the top and the sport leagues down the left-most column. Then, I could update just this table as the surveys changed and different Blocks had to be shown.
League | BlockA | BlockB | BlockC | Block...
MLB | TRUE | TRUE | TRUE ...
EPL | TRUE | TRUE | FALSE ...
NCAA | TRUE | FALSE | FALSE ...
Can I create a lookup table like this? And if so, how do I read from it and write the data back into an embedded data field?
One idea I had was creating a "contact list" with the leagues as contacts and a bunch of custom fields. That would probably work as a workaround, but there are several other reasons why I don't like that approach.
Could I just create this "table" as a matrix in JavaScript? Then I could iterate through all the entries and check to see if it matches what the user picked? I've used JavaScript, but I'm not great at it.
Of course, if there's a completely different approach I should use, I'm open to ideas.
Many thanks,
David
(for the record, I actually don't like VLOOKUP in Excel. I use INDEX/MATCH exclusively, but more people know VLOOKUP, which is why I used it in the TL;DR)
Best answer by TomG
Use a JavaScript object to define your flags:
```
var table = {
MLB: { A: true, B: true, C: true, etc.},
EPL: {A: true, B: true, C: false, etc.},
...etc...
};
```
Then pipe the league into the JavaScript to lookup the league in your table (e.g., `table["${e://Field/league}"]`), and loop through the league's block object and set your embedded data variables appropriately.
View originalLeave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.