How to randomly select two selected answers from Pick, Group and Rank | XM Community
Skip to main content
Question

How to randomly select two selected answers from Pick, Group and Rank

  • July 13, 2022
  • 3 replies
  • 21 views

Forum|alt.badge.img

Hi,
I have a pick group and rank question with 5 groups, very unlikely to very likely. I need to randomly select up to two answers from the very unlikely and unlikely groups and pipe those into the text of the follow up question.
The follow up question would read like this
What makes you say you are unlikely to consider mobile ordering and self checkout.
Any help would be appreciated. Thanks,

3 replies

grahulp5
QPN Level 3 ●●●
Forum|alt.badge.img+13
  • QPN Level 3 ●●●
  • July 14, 2022

get them in the next question and then use subset feature of the randomization in single punch question. Then pipe them to whichever question you need to.


Forum|alt.badge.img
  • Author
  • July 14, 2022

What I ended up doing is grabbing the answer codes (choiceid) from the DOM, randomizing and selecting two. Then storing in embedded data.
Qualtrics.SurveyEngine.addOnUnload(function()
{
/*Place your JavaScript here to run when the page is unloaded*/
var $this = jQuery(this.questionContainer);
var arr=[];
var $groupUl;
Qualtrics.SurveyEngine.setEmbeddedData("Q28_Selected_Unlikely_Codes", "");
jQuery(".QuestionBody .groupsContainerTd .Group", $this).each(function (i) {
$groupUl = jQuery(this).find("ul.ui-sortable");
jQuery("li", $groupUl).each(function (i) {
var groupText=jQuery(this).closest(":has(h2)").find("h2").text().toUpperCase();
if(groupText.indexOf("UNLIKELY") >= 0 && groupText.indexOf("NOR") == -1) {
arr.push(jQuery(this).data("choiceid"));
}
});
});
const shuffled = [...arr].sort(() => 0.5 - Math.random());
selected=shuffled.slice(0, 2);
Qualtrics.SurveyEngine.setEmbeddedData("Q28_Selected_Unlikely_Codes", selected.join());
});

Then creating a multiple response question and setting the answers and auto submit so I can then use piped text.
Qualtrics.SurveyEngine.addOnReady(function()
{
/*Place your JavaScript here to run when the page is fully displayed*/
var val=Qualtrics.SurveyEngine.getEmbeddedData("Q28_Selected_Unlikely_Codes").split(",");
for (var i = 0; i < val.length; i++) {
this.setChoiceValueByRecodeValue(val[i],true);
}
this.clickNextButton();
});

Don't know if this was the best method, but it's working.


grahulp5
QPN Level 3 ●●●
Forum|alt.badge.img+13
  • QPN Level 3 ●●●
  • July 15, 2022

Kudos! We could have used qualtrics to pick by default using randomization but this is fine as long as it works!