Specific embedded data variables don't export correctly

emmanuelemmanuel Jerusalem, IsraelCommunity Member Qubie ✭
edited May 2020 in Custom Code

Specific embedded data variables don't export correctly

Hi there,

This is a follow-up question on a previous question I had posted about here. In short, I use JavaScript to randomly sample a set of numbers, then assign that set to an embedded data variable. Then, I use that set of numbers as an indicator in a Loop&Merge block, to either hide or show a certain question in the Loop, according to the loop iteration. This setup works well, but unfortunately, when I review the exported data, I see that the embedded data variable that holds the set simply doesn't get exported correctly. Instead of a set of 20 numbers, I see only one number in the exported data. This is particularly strange because not only does the loop&merge mechanism follow the set of numbers *retrieved from* the embedded data, but also because when I do a "sanity check" and pipe the embedded data variable into a survey question, I can see the set of numbers in its entirety.

Does someone have an idea why a set of numbers (though defined as a string of characters, but it shouldn't matter) assigned to an embedded data doesn't get exported fully?

For reference, here's the JS code generating and assigning the set of numbers to embedded data:

	/*Place your JavaScript here to run when the page is fully displayed*/
// the following function randomly subsets a list of numbers
// inspired by: https://stackoverflow.com/a/11935263/6105259
	    function getRandomSubarray(arr, size) {
    var shuffled = arr.slice(0), i = arr.length, temp, index;
    while (i--) {
        index = Math.floor((i + 1) * Math.random());
        temp = shuffled[index];
        shuffled[index] = shuffled[i];
        shuffled[i] = temp;
    return shuffled.slice(0, size);

// we want to define the total number of trials in the block. in this case we have 30 trials
var x = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30];

// say that we want a question to appear in only 30% of trials. therefore, for a total of 30 trials, the question will appear only in 10. in other words, the question will be hidden in 20 trials. let's randomly subset the 20 trials where the question will be hidden, sing the function defined above:
var twentyRandomMembers = getRandomSubarray(x, 20);

// finally, assign the resultant list of 20 numbers to an embedded data variable	
Qualtrics.SurveyEngine.setEmbeddedData('twenty_sampled_numbers_block_one', twentyRandomMembers);



Best Answer

  • TomGTomG Raleigh, NCCommunity Member Wizard ✭✭✭✭✭
    Accepted Answer

    twentyRandomMembers is an array. You should convert it to a string before saving as embedded data:

    Qualtrics.SurveyEngine.setEmbeddedData('twenty_sampled_numbers_block_one', twentyRandomMembers.join(","));

Sign In to Comment