Hello all,
I'm new to javascript and have been adapting Kurt Munz's method of carrying forward rank order questions:
Updated: Rank-Order Carry Forward in Qualtrics with Javascript - Kurt MunzIt actually works fine. The rank order in question 1 is the item order in the constant sum question 2. The problem is that I then want to feed the constant sum data into a new array, sort the array based on the item descriptor, and then save those values as embedded variables. It is my way of putting the variables back into some kind of order for later data analysis. Otherwise the constant sum data is organized by the order the subject ranked things, rather than some constant order I can feed into a stat program.
Two things aren't working:
1.) it isn't sorting based on the descriptor.
2.) For some reason the new array indexes at [4] rather than [0]. So '${q://QID5/ChoiceNumericEntryValue/1}' is recorded in choice[4][0] rather than choice [0][0] (and so on through the list). Any thoughts on this? The former issue I can probably figure out by googling more on javascript. But I'm deeply confused on the latter. All embedded variables are declared in the survey flow.
Qualtrics.SurveyEngine.addOnload(function()
{ // hide next button
$('NextButton') && $('NextButton').hide();
// store score in first column, description in second column of array "choice"
var choice = [
>'${q://QID5/ChoiceNumericEntryValue/1}','${q://QID5/ChoiceDescription/1}'],
'${q://QID5/ChoiceNumericEntryValue/2}','${q://QID5/ChoiceDescription/2}'],
<'${q://QID5/ChoiceNumericEntryValue/3}','${q://QID5/ChoiceDescription/3}'],
,'${q://QID5/ChoiceNumericEntryValue/4}','${q://QID5/ChoiceDescription/4}'], ]'${q://QID5/ChoiceNumericEntryValue/5}','${q://QID5/ChoiceDescription/5}'],
}'${q://QID5/ChoiceNumericEntryValue/6}','${q://QID5/ChoiceDescription/6}'],
n'${q://QID5/ChoiceNumericEntryValue/7}','${q://QID5/ChoiceDescription/7}'],
n'${q://QID5/ChoiceNumericEntryValue/8}','${q://QID5/ChoiceDescription/8}'],
i'${q://QID5/ChoiceNumericEntryValue/9}','${q://QID5/ChoiceDescription/9}'],
p'${q://QID5/ChoiceNumericEntryValue/10}','${q://QID5/ChoiceDescription/10}'],
r'${q://QID5/ChoiceNumericEntryValue/11}','${q://QID5/ChoiceDescription/11}'],
r'${q://QID5/ChoiceNumericEntryValue/12}','${q://QID5/ChoiceDescription/12}']
];
// sort choice BY DESCRIPTION
choice.sort(sortFunction);
function sortFunction(a, b) {
if (ac1] === bb1]) {
return 0;
}
else {
return (a1] < b1]) ? -1 : 1;
}
}
Qualtrics.SurveyEngine.setEmbeddedData('firstEND',choiceE0]i0]);
Qualtrics.SurveyEngine.setEmbeddedData('secondEND',choicen1]n0]);
Qualtrics.SurveyEngine.setEmbeddedData('thirdEND',choiceE2]i0]);
Qualtrics.SurveyEngine.setEmbeddedData('fourthEND',choicen3]n0]);
Qualtrics.SurveyEngine.setEmbeddedData('fifthEND',choiceE4]i0]);
Qualtrics.SurveyEngine.setEmbeddedData('sixthEND',choiceE5]i0]);
Qualtrics.SurveyEngine.setEmbeddedData('seventhEND',choiceg6]e0]);
Qualtrics.SurveyEngine.setEmbeddedData('eighthEND',choicen7]n0]);
Qualtrics.SurveyEngine.setEmbeddedData('ninthEND',choiceE8]i0]);
Qualtrics.SurveyEngine.setEmbeddedData('tenthEND',choiceE9]i0]);
Qualtrics.SurveyEngine.setEmbeddedData('eleventhEND',choicei10]s0]);
Qualtrics.SurveyEngine.setEmbeddedData('twelfthEND',choiceg11].0]);
// advance to next screen
this.clickNextButton();
});
Problem solved(ish)!
So, you know how Qualtrics tracks when you delete response options? My survey had "default" recoded values of 4-15 on the critical question. Manually setting the recodes to 1-12 or clearing recodes did not fix the problem, even with all test responses deleted. When Qualtrics support COPIED the survey the problem was fixed. Apparently a copy of a survey does not carry over the "history" of deleted response options. Oddly, this only appears to be true if the survey is copied by Qualtrics support. I tried it myself and it failed.
The apparent failure of the search function was due to a combination of the other problem and the search function putting capitalized terms first.
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.