access recode values from a random question | XM Community
Solved

access recode values from a random question

  • 16 January 2019
  • 2 replies
  • 16 views

Hi,

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.
icon

Best answer by bstrahin 16 January 2019, 15:41

View original

2 replies

Userlevel 7
Badge +38
@HanH this can all be done without code using features in Qualtrics. See the attached .qsf file and explanation below. I built your requirements on a smaller scale but you should be able to replicate it for the 36 questions you need.

1. Build all of your survey questions in one block
2. In the editor, use Block Options - Question Randomization - Present only (and where 1 put 2, you would put 9)
3. Back in the main editor, you will change the recode values to the rewards you want as you talked about doing in your post
4. Under Survey Flow
* Show your question block
* Set embedded data for reward1 through reward36 where each variable pipes in SelectedChoicesRecode from the appropriate question
* Then insert a randomizer to set your reward value (show 1). There will be 36 pairs of elements embedded under your randomizer. A branch to make sure that the question was asked (reward1-36 is not empty for the iteration you are on) and then it will set the variable reward to the recode value for the appropriate question number
* The last element is a second block that shows the reward value and is only there for testing
Amazing! I can understand the logic of the solution from your explanation. I will try them out later.
Thank you so much!

Leave a Reply