save Multichoice response text answer in embedded data. | XM Community
Skip to main content

Hi there,

I already asked before but still didnt manage to get a great result. TI am trying to test if the Answers of QID171 (multi choice respons) can be saved seperated in email1, email2, email3. This is the script Im trying to let it work but I have no idea why its not working.

Qualtrics.SurveyEngine.addOnload(function() {

// Replace 'QID171' with the actual question ID var questionId = 'QID171';

// Get the selected choices from the multi-choice question

var selectedChoices = Qualtrics.SurveyEngine.getSelectedChoices(questionId);

// Set each selected option in separate embedded data fields for

(var i = 0; i < selectedChoices.length; i++) { var embeddedDataName = 'email' + (i + 1); var selectedChoiceText = jQuery("#" + questionId + " label[qid='" + selectedChoices[i] + "']").text().trim();

Qualtrics.SurveyEngine.setEmbeddedData(embeddedDataName, selectedChoiceText); } });

 

A loop like this should be great but Im also willing to just write it down for 5 email embedded data. The problem is that I can't get the answers splitted or maybe dont know how.

 

@celinoto

 

Try below code:
The only issue you had was with selectedChoices variable.
Additionally, you can use this.questionId if you want specific questions questionId instead of manually entering.

Qualtrics.SurveyEngine.addOnReady(function() {
// Replace 'QID171' with the actual question ID
var questionId = 'QID171';

// Get the selected choices from the multi-choice question
var selectedChoices = this.getSelectedChoices();

// Set each selected option in separate embedded data fields
for (var i = 0; i < selectedChoices.length; i++) {
var embeddedDataName = 'email' + (i + 1);
var selectedChoiceText = jQuery("#" + questionId + "-" + selectedChoicessi] + "-label").text().trim();


Qualtrics.SurveyEngine.setEmbeddedData(embeddedDataName, selectedChoiceText);
}
});

Hope it helps!


@celinoto

 

Try below code:
The only issue you had was with selectedChoices variable.
Additionally, you can use this.questionId if you want specific questions questionId instead of manually entering.

Qualtrics.SurveyEngine.addOnReady(function() {
// Replace 'QID171' with the actual question ID
var questionId = 'QID171';

// Get the selected choices from the multi-choice question
var selectedChoices = this.getSelectedChoices();

// Set each selected option in separate embedded data fields
for (var i = 0; i < selectedChoices.length; i++) {
var embeddedDataName = 'email' + (i + 1);
var selectedChoiceText = jQuery("#" + questionId + "-" + selectedChoicessi] + "-label").text().trim();


Qualtrics.SurveyEngine.setEmbeddedData(embeddedDataName, selectedChoiceText);
}
});

Hope it helps!




Hi There, 

It still seems that it doesn't work…. I tried to set the code in addonReady and in the addonload function...


Try using addonPageSubmit

Qualtrics.SurveyEngine.addOnPageSubmit(function()

{

Code

}

 


Leave a Reply