Hello,
I am trying to pipe 2nd and 3rd rank options from a ranking question but it is not working through native options. Have tried to apply JavaScript custom code but that too is not piping the text. Below is the code. It would be help if there can be some solution on this requirement.
<script>
/*
captureRanks v2.x
Captures ranked choice labels and recodes from Qualtrics Rank Order questions
and stores them in Embedded Data for piping.
Usage: In the questions JavaScript
captureRanks(this, { prefix: "QID38" });
*/
function captureRanks(q, options) {
options = options || {};
var prefix = options.prefix || q.questionId;
var choices = q.getChoices();
var answers = q.getAnswers();
var ranks = [];
// Build array of {choiceId, rank}
for (var c in choices) {
var rank = q.getChoiceValue(c);
if (rank && rank !== "") {
ranks.push({
choiceId: c,
rank: parseInt(rank, 10)
});
}
}
// Sort by rank (1 = highest)
ranks.sort(function (a, b) {
return a.rank - b.rank;
});
// Write to Embedded Data
for (var i = 0; i < ranks.length; i++) {
var pos = i + 1;
var cid = ranks[i].choiceId;
Qualtrics.SurveyEngine.setEmbeddedData(
prefix + ".rank.text." + pos,
choices[cid]
);
Qualtrics.SurveyEngine.setEmbeddedData(
prefix + ".rank.recode." + pos,
answers[cid] || cid
);
}
}
</script>
-----------------------------------------------------------------------------------------------------------
The piping code in the follow up question -
${e://Field/QID38.rank.text.2}.'
-----------------------------------------------------------------------------------------------------------
