Randomize Qualtrics Question Order Within Block Based on Embedded Data

22 hours ago 3
ARTICLE AD BOX

I am programming a qualtrics survey. I have multiple blocks and I want to randomize the order of questions within the block once, so that the order is maintained throughout the whole survey.

The issue is that there are multiple tasks, so I can't just create additional randomizers in the survey flow every single time.

Suppose my questions are all slider questions:

task1_support: How much would you support the party?

task1_like: How much do you like the party?

task1_help: How much would you help the party?

which come after a vignette with the party:

vignette1: "Party X is doing Y in country Z...."

And then for the other tasks I ask the same thing:

vignette2: "Party J is doing K in country L...."

task2_support: How much would you support the party?

task2_like: How much do you like the party?

task2_help: How much would you help the party?

I want to set embedded data one like the following:

outcome_order = { support_like_help, support_help_like, like_help_support, like_support_help, help_support_like, help_like_support }

I randomly pick one of those 6 options, assigning an order. Suppose I pick "like_help_support". Then for eveyr task I should see:

Vignette1:

task1_like: How much do you like the party?

task1_help: How much would you help the party?

task1_support: How much would you support the party?

Vignette2:

task2_like: How much do you like the party?

task2_help: How much would you help the party?

task2_support: How much would you support the party?

I have tried editing the js for a blank preceding question in the block like the following:

Qualtrics.SurveyEngine.addOnReady(function() { var self = this; var outcomeOrderStr = "${e://Field/outcome_order}"; // Debug line - check if embedded data is piping in console.log("Order is: " + outcomeOrderStr); if (!outcomeOrderStr || outcomeOrderStr.indexOf('Field') > -1) { console.warn("Embedded data not piping correctly"); return; } var orderArray = outcomeOrderStr.split('_'); console.log("Order array: " + orderArray); // ---- STRATEGY: find questions by QID ---- // In Qualtrics, every question block has an ID like "QID123" // Your export tags (conjoint_1_med_conf etc.) appear in the QID div // We search all QuestionOuter divs and match by export tag in the id attribute directly var allQuestions = jQuery('.QuestionOuter'); console.log("Total questions found: " + allQuestions.length); allQuestions.each(function(i) { console.log("Q" + i + " id=" + jQuery(this).attr('id')); }); // Map your tokens to export tag fragments // Try multiple possible patterns Qualtrics might use var tagMap = { "like": ["like", "task_1_like"], "support": ["support", "task_1_support"], "help": ["help", "task_1_help"] }; function findQuestion(key) { var patterns = tagMap[key]; var found = null; // Try 1: match against the QuestionOuter id attribute jQuery('.QuestionOuter').each(function() { var id = jQuery(this).attr('id') || ''; for (var p = 0; p < patterns.length; p++) { if (id.indexOf(patterns[p]) > -1) { found = jQuery(this); return false; } } }); if (found) { console.log("Found " + key + " by ID"); return found; } // Try 2: match anywhere in the full HTML of the QuestionOuter jQuery('.QuestionOuter').each(function() { var html = jQuery(this).html() || ''; for (var p = 0; p < patterns.length; p++) { if (html.indexOf(patterns[p]) > -1) { found = jQuery(this); return false; } } }); if (found) { console.log("Found " + key + " by HTML"); return found; } console.warn("Could not find question for: " + key); return null; } // Set up flex container var container = jQuery(self.getQuestionContainer()).closest('.QuestionOuter').parent(); console.log("Container tag: " + container.prop('tagName') + " id=" + container.attr('id')); container.css({ "display": "flex", "flex-direction": "column" }); // Pin dummy to top jQuery(self.getQuestionContainer()).closest('.QuestionOuter').css("order", "0"); // Apply order orderArray.forEach(function(key, index) { var q = findQuestion(key); if (q) { q.css("order", (index + 1) * 10); console.log("Set order " + ((index+1)*10) + " for " + key); } }); });

However this causes 1 of the outcomes to show up sometimes, but other times nothing renders. So this code doesn't work.

I can't use randomizers and create extra blocks because I have too many vignettes to make it feasible. How can I define the order of the questions directly from the embedded data?

Read Entire Article