Why does setEmbeddedData not work? | XM Community
Skip to main content

I am trying to load a list of labels (separated by commas), randomly remove one, display it, and store the remaining labels as embedded data. The following code manages to do all but the last one. That is console.log(backup_label) outputs the list of remaining labels but it is not saved to the embedded data. Does anyone know why the setEmbeddedData method does not seem to work from within questionclick function or is there maybe a way of passing the backup_label variable somewhere else in order to then use the setEmbeddedData method?
Qualtrics.SurveyEngine.addOnload(function()
{
this.questionclick = function(event,element){
if (element.type == 'checkbox') {
var backup_label = "${e://Field/backup_label}";
backup_label = backup_label.split(",");
i = Math.floor(Math.random() * backup_label.length);
var current_label = backup_label.splice(i, 1); //remove random label
backup_label = backup_label.join(); //join remaining labels
document.querySelector("#label").innerText = current_label; //display label

console.log(backup_label);
Qualtrics.SurveyEngine.setEmbeddedData('backup_label',backup_label);
}
}
});

Your code looks fine. Except that I would join with "," since you are splitting using that.
However, what do you mean by setED doesn't work. Where are you testing it?


https://www.qualtrics.com/community/discussion/comment/38273#Comment_38273Thanks for your reply. The joining worked fine because "," is the default separator. I know that setED does not work because no matter how many backup labels I remove from the list (by clicking on the checkbox), the backup_label variable has still it's original length when I download the data.
I also show the block containing this code repeatedly during the survey and every time console.log(backup_label) outputs a list of the original length - 1, even if I clicked on the checkbox multiple times in the block before.


You should get in touch with support for this.


Leave a Reply