I've been stuck at this issue for some time and any help would be much appreciated.
I would like to design a survey with the following features:
1. Display a random subset of 9 questions from a total of 36 questions.
2. Reward each participant for his/her answer for a question randomly selected from the displayed questions. Different answers give different amount of rewards.
So, the way I have thought about this is to set the recode values of the answers to the appropriate rewards and the get the recode values. But I can't seem to do so. Here's what I have tried:
At the start of the survey, set embedded data rand to a random integer between 1 and 9.
Then, each question has this code added:
```
var qId = this.questionId;
Qualtrics.SurveyEngine.setEmbeddedData("qId", "${e://Field/qId}" + "." + qId);
```
Then, after the block of questions, add this script:
```
var rand = parseInt("${e://Field/rand}");
var qString = "${e://Field/qId}";
var qArray = qString.split(".");
var rId = qArray[rand];
```
Then rObj is Qualtrics-SurveyEngine-getInstance(rId); (sorry for breaking the code format but for some reason, the post does not like this line and I kept getting denied permission to post. The "-" is actually ".")
```
var rAns = rObj.getSelectedChoices()[0];
var rBonus = rObj.getChoiceRecodeValue(rAns);
Qualtrics.SurveyEngine.setEmbeddedData("rBonus", rBonus);
```
Then it seems to me that everything works up to rAns but the rBonus line returns blank.
Please let me know if you have any solutions to this.
Best answer by bstrahin
View original