I am currently putting together a survey that consists of 20 identical questions, and I want to embed in each of the questions piped text from custom javascript code that will pull randomly without replacement from an array of 80 names (produced as strings) for each participant. So, each participant will be randomly assigned 20 of the 80 names, and each name will be shown piped into the question for each of the 20 identical questions. How can I do this? I am pretty unfamiliar with Javascript and the integration with Qualtrics. Any attempt I try at doing this outside of Qualtrics in a standard Javascript compiler seems to have run time errors.... is this due to a large array of strings? Any help in advance would be much appreciated.
Cheers!
Nicholas
If I understand your conundrum correctly, perhaps you can do the following.
First create 20 blank embedded data variables before the usage of your JS code - say from 1 to 20.
Then, use JS to create an array of 20 random names from the pool of 80. Then, loop through the array and set each of the names as a value to each of your newly created blank variables. So `Qualtrics.SurveyEngine.setEmbeddedData( '1', nameArray[0]);`
`Qualtrics.SurveyEngine.setEmbeddedData( '2', nameArray[1]);`
`Qualtrics.SurveyEngine.setEmbeddedData( '3', nameArray[2]);`
etc
Then just pull the embedded data values in your questions via Piped Text.
Hope that helps.
Nikolay
That's actually what I exactly ended up doing. Thanks for the confirmation that this is an approved method.
Cheers!
Nikolay
npetrov937 and gametheoryguy93
Could you please publish how to do this in js? I'm not very familiar with js coding and I have a similar issue now with Qualtrics. In addition - can the vector be filled from a csv file? Specificly, I have a dataset saved in a csv, where each observation (row) has some columns. Then, when I randomly select 20 out of 80, for example, I choose 20 rows and then I use all the columns' values of these rows [e.g. I display to the user a name, then an ID, then an address etc. - so multiple values are extracted for each selectd row]. What's the best way to do this?
Thanks in advance!
Would also love to see the code for the loop here and get some more detail on the order of operations if possible. I'm a JS newbie, thanks!
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.