Grouping randomized items together, but making one item fixed | Experience Community
Skip to main content
Question

Grouping randomized items together, but making one item fixed

  • June 29, 2026
  • 2 replies
  • 20 views

Hi all,

I want to create a list of 15 multiple choices which will be grouped together into 3 groups for better display.

I want to randomize all items within each of the 3 groups, EXCEPT for one item within each group which I want to keep fixed as the last item displayed within the group.

Is there a way to do this? I have managed to randomize all items within each group, but I cannot seem to figure out how to make one of them fixed.

2 replies

vgayraud
QPN Level 7 ●●●●●●●
Forum|alt.badge.img+65
  • QPN Level 7 ●●●●●●●
  • June 29, 2026

Hi ​@rravaz 

This is probably overkill for your use case, but here’s a custom randomizer for groups for NSTE.

Qualtrics.SurveyEngine.addOnReady(function () {
// CONFIG
// One entry per group, in display order. Each group is an ORDERED list of
// blocks. Blocks render top to bottom in the order they appear here.
// Each block:
// { type: "fixed", ids: [...] } -> rendered in this exact order
// { type: "shuffle", ids: [...] } -> randomized among themselves
//
// You can declare as many blocks of either type as you want, in any order,
// e.g. fixed -> shuffle -> shuffle -> fixed. The final group order is the
// blocks concatenated in sequence, with shuffle blocks randomized internally.
const GROUPS = [
[
{ type: "shuffle", ids: [1, 2] },
{ type: "fixed", ids: [3] }
],
[
{ type: "fixed", ids: [4] },
{ type: "shuffle", ids: [5] },
{ type: "fixed", ids: [6] }
],
[
{ type: "shuffle", ids: [7, 8] },
{ type: "fixed", ids: [9] }
]
];

// Set DEBUG to true to log original and computed order to the console.
const DEBUG = false;

// UTILITIES
const log = function () {
if (DEBUG && window.console && console.log) {
console.log.apply(console, arguments);
}
};

const shuffle = function (arr) {
const out = arr.slice();
for (let i = out.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
const tmp = out[i];
out[i] = out[j];
out[j] = tmp;
}
return out;
};

// Build display order for one group by walking its blocks in order. Fixed
// blocks keep their listed order; shuffle blocks are randomized. IDs the API
// does not report as present are dropped.
const orderGroup = function (blocks, validIds) {
let order = [];
(blocks || []).forEach(function (block) {
const present = (block.ids || []).filter(function (id) {
return validIds.indexOf(id) !== -1;
});
const seq = block.type === "shuffle" ? shuffle(present) : present;
order = order.concat(seq);
});
return order;
};

// HOOKS
// Capture the question instance once for use in nested function expressions.
const self = this;

// Retrieve real choice IDs from the API in display order.
const apiChoices = self.getChoices();
if (!apiChoices || apiChoices.length === 0) {
return;
}
log("[Qualtrics] getChoices() ->", apiChoices);

const validIds = apiChoices.map(function (c) {
return parseInt(c, 10);
});

// DISCOVERY HELPER
// When DEBUG is on, log the choice IDs found in each group container so you
// can copy the exact IDs and group membership straight into the CONFIG.
// Group membership is not exposed by the API, so this reads it from the DOM.
if (DEBUG) {
const qc = self.getQuestionContainer();
if (qc) {
const groupEls = qc.querySelectorAll(".choice-group");
for (let gi = 0; gi < groupEls.length; gi++) {
const inputs = groupEls[gi].querySelectorAll(
'input[id^="mc-choice-input-"]'
);
const foundIds = [];
for (let ii = 0; ii < inputs.length; ii++) {
const parts = inputs[ii].id.split("-");
foundIds.push(parseInt(parts[parts.length - 1], 10));
}
log("[Qualtrics] DISCOVERY Group " + (gi + 1) +
" choice IDs (DOM order):", foundIds);
}
}
}

// Resolve a choice's DOM row and its owning group container.
const choiceRowFor = function (choiceId) {
const input = document.getElementById(
"mc-choice-input-" + self.questionId + "-" + choiceId
);
if (!input) {
return null;
}
let el = input;
while (el) {
if (el.parentNode && el.parentNode.className &&
el.parentNode.className.indexOf("choice-group") !== -1) {
return { row: el, group: el.parentNode };
}
el = el.parentNode;
}
return null;
};

// Apply computed order within each group by re-appending rows in sequence.
GROUPS.forEach(function (blocks, idx) {
const order = orderGroup(blocks, validIds);
log("[Qualtrics] Group " + (idx + 1) + " -> order:", order);
order.forEach(function (choiceId) {
const found = choiceRowFor(choiceId);
if (found) {
found.group.appendChild(found.row);
}
});
});
});

 


pamelalbeck
Level 5 ●●●●●
Forum|alt.badge.img+41
  • Level 5 ●●●●●
  • June 29, 2026

Advanced randomization if you want to leave one of the answers fixed may help: https://www.qualtrics.com/support/survey-platform/survey-module/block-options/question-randomization/