Unique Image ID on Unique Element and not Position of Element in Randomized Array | XM Community
Question

Unique Image ID on Unique Element and not Position of Element in Randomized Array

  • 23 March 2020
  • 0 replies
  • 6 views

I am doing some image randomization in Qualtrics and I am having some trouble attaching a unique image identifier to the image URL.

So below is my randomization code:

function shuffle(array){
var currentIndex = array.length, temporaryValue, randomIndex;
while (0 !== currentIndex){
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;
}
return array;
}

var graf = [
"https://uebs.eu.qualtrics.com/CP/Graphic.php?IM=IM_1z9XtqMMcxwzT5b",
"https://uebs.eu.qualtrics.com/CP/Graphic.php?IM=IM_1GPM6xjXNfqEz0p",
"https://uebs.eu.qualtrics.com/CP/Graphic.php?IM=IM_24zsJ8x7khvTyfz",
"https://uebs.eu.qualtrics.com/CP/Graphic.php?IM=IM_2gE99I1wnqLf8Al",
"https://uebs.eu.qualtrics.com/CP/Graphic.php?IM=IM_cA6grOdEgKclDwN",
"https://uebs.eu.qualtrics.com/CP/Graphic.php?IM=IM_1MpQXKFhvKEZzy5",
"https://uebs.eu.qualtrics.com/CP/Graphic.php?IM=IM_5yCccbIau1oVeYd",
"https://uebs.eu.qualtrics.com/CP/Graphic.php?IM=IM_etjgo74oXjzcbat",
"https://uebs.eu.qualtrics.com/CP/Graphic.php?IM=IM_1U0smHG8iaNu029",
"https://uebs.eu.qualtrics.com/CP/Graphic.php?IM=IM_6yhCCH333SZT9Od",
"https://uebs.eu.qualtrics.com/CP/Graphic.php?IM=IM_dm6sAu55TES6lxz",
"https://uebs.eu.qualtrics.com/CP/Graphic.php?IM=IM_6KY6cciHNIgjBvD",
"https://uebs.eu.qualtrics.com/CP/Graphic.php?IM=IM_79gaUXUzgoz0PXv",
"https://uebs.eu.qualtrics.com/CP/Graphic.php?IM=IM_4GBxFmVJQ1C7LM1",
"https://uebs.eu.qualtrics.com/CP/Graphic.php?IM=IM_0lBriWEzta6YDKB",
"https://uebs.eu.qualtrics.com/CP/Graphic.php?IM=IM_77GetFOthNBbhoV",
"https://uebs.eu.qualtrics.com/CP/Graphic.php?IM=IM_cBd1svYuFqYg36B",
"https://uebs.eu.qualtrics.com/CP/Graphic.php?IM=IM_6R8Qz7FEx6Fc90h",
"https://uebs.eu.qualtrics.com/CP/Graphic.php?IM=IM_1Xi04o1mv5Z1OC1",
"https://uebs.eu.qualtrics.com/CP/Graphic.php?IM=IM_a4uQ0W0GUf01mLj",
"https://uebs.eu.qualtrics.com/CP/Graphic.php?IM=IM_cNgPIEvG3KwUYnz",
];

graf = shuffle(graf);
console.log(graf);

Qualtrics.SurveyEngine.setEmbeddedData('graffiti1', graf[0]);
Qualtrics.SurveyEngine.setEmbeddedData('graffiti2', graf[1]);

I then embedded data block for "graffiti1" & "graffiti2" to pipe them into the HTML code. My issue is that for each survey respondent the order of the array is different and therefore my embedded data fields are not uniquely tracking a particular image URL. How do I give each image URL a unique identifier that follows the element and not the position within the array?

I am assuming the fix to this is quite simple and I am overthinking it. I originally tried loop and merge and pasted all my Image URLs into Field 1 and my Image IDs in Field 2 (in the same order), but I could not find the proper pipe text to pull the first two rows into my question after the loop randomized.... if that makes sense?

Any help would be great! Thanks in advance!

0 replies

Be the first to reply!

Leave a Reply