Solved
Javascript Embedded Name Randomization Across Questions
Hello,
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
Best answer by npetrov937
Hi 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
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.
