How to save answers from a matrix table into embedded data while on the same page? | XM Community
Skip to main content

Hello! I have a loop&merge block that goes through 3 loops and the question on the page is a 17-statement bipolar matrix table. I would like to save the recoded answers from the matrix table on each page into an embedded variable. I am trying to do this by looping over all the statement answers and adding them to an array and then converting the array to a string. This is my current JavaScript code, which is on the matrix table question itself:
// Save answer choice after page is submitted
Qualtrics.SurveyEngine.addOnPageSubmit(function() 
{
// Pull MPL counter
var counter = parseInt("${e://Field/counter}");
var prefix = "xnorm_" + counter;

// Get question ID
var inputID = String(this.questionId);
Qualtrics.SurveyEngine.setEmbeddedData("inputID", inputID);

// Initialize array of choices
var choices = new Array(17);

// Initialize statement counter
var j = 1;

// Loop over the array & statement answers
for (var i = 0; i < 17; i++) {
choicessi] = "${q://" + inputID + "/SelectedAnswerRecode/" + j + "}";
j++;
}

// Save array as string
Qualtrics.SurveyEngine.setEmbeddedData(prefix+"Choices", choices.join(","));
});
However, when I pipe the embedded data variable that stores this (e.g. xnorm_1Choices), it just prints a string of 15 commas, like this.

,,,,,,,,,,,,,,,,

Any ideas on how I can fix this so it actually saves the answers? Thanks!

Be the first to reply!

Leave a Reply