Block Branching based off of Pick Sort Rank question - possible with JavaScript? | XM Community
Skip to main content

Hi all, I’m building a survey that branches to different blocks depending on a Pick Sort Rank question. The four buckets I have participants sort statements into are a) heard of, b) tried to use, c) use, d) no longer use.

I want to show a block if the corresponding bucket  has at least one statement in it. Qualtrics support told me that I have to make a chain of conditional logic statements for each statement in the corresponding bucket. I have 45 statements and 3 or so blocks, depending, so I’d really really prefer not to.

Is javascript the answer to my problems? PS I’m not experienced with this so please explain how to implement it simply.

Thank you!

This can be put in place with JS by first creating the Embedded Data Fields of "group1filled", "group2filled", "group3filled", and "group4filled". Put these at the top of the Survey Flow.

Then on the PGR question, add the below to the question's JavaScript in the OnReady section. Each time a respondent places a statement in one of the Groups and after a half second delay, the Embedded Data fields are set with "yes" or "no" based on a statement existing in the Group or not. You can then use "group1filled" is equal to "yes" as a part of Branching or Display logic.

var qid = this.questionId;

jQuery("#"+qid+" .QuestionBody").on("mouseup , touchend", function() {

setTimeout(function() {

var group1count = jQuery("#"+qid+"group0").children().length;
var group2count = jQuery("#"+qid+"group1").children().length;
var group3count = jQuery("#"+qid+"group2").children().length;
var group4count = jQuery("#"+qid+"group3").children().length;

if (group1count > 0) {
Qualtrics.SurveyEngine.setEmbeddedData("group1filled","yes");
}else{
Qualtrics.SurveyEngine.setEmbeddedData("group1filled","no");
}

if (group2count > 0) {
Qualtrics.SurveyEngine.setEmbeddedData("group2filled","yes");
}else{
Qualtrics.SurveyEngine.setEmbeddedData("group2filled","no");
}

if (group3count > 0) {
Qualtrics.SurveyEngine.setEmbeddedData("group3filled","yes");
}else{
Qualtrics.SurveyEngine.setEmbeddedData("group3filled","no");
}

if (group4count > 0) {
Qualtrics.SurveyEngine.setEmbeddedData("group4filled","yes");
}else{
Qualtrics.SurveyEngine.setEmbeddedData("group4filled","no");
}

}, 500);

});

 


Leave a Reply