Set embedded data to choice value when (MC) choice is selected | XM Community
Skip to main content

Hello, I would much appreciate some help. I'm not well-versed in Javascript so I go by examples.
I have a multiple choice question that is populated with data from a webservice. I get and embed the answer options at the start of the survey flow. For Q5 in this case, I used piped text to show the embedded data (e.g. data.0.name, data.1.name, data.2.name, etc.) as answer options.
The data I get from the webservice is dynamic, meaning that

data.0.name
is sometimes choice A and sometimes choice B (or Z, it's a list of 100 ranked items).
To analyse how often each choice is checked, I want to create a variable with the
choiceValue
that is displayed and selected, rather than the original embedded data.

I found and tried adding this snippet as JavaScript to Q5 :
Qualtrics.SurveyEngine.addOnPagcheSubmit(function()
{
if(jQuery("#"+this.questionID+" input[type='checkbox']:checked").attr("choiceId", "1" {
Qualtrics.SurveyEngine.setEmbeddedData("data.0.name", "Test");
});

Alternative 1
Not use the webservice, but I would prefer to find a way to always include this dynamic 'top 100' list, as I suspect it will vary over the course of the year
Alternative 2
Add as embedded data
${q://QID5/ChoiceGroup/SelectedChoices}
. However, as far as I know in this case I get one variable with multiple choices, that I'd need to split to get choice counts I can analyze. Any suggestions on how to split the embedded data would be very helpful in this case

I think your stated Alternative 2 would work. When you're setting your embedded data for that in the Survey Flow, try clicking on "options" and changing the type to "Multi-Value Text Set." That should automatically split up the list of selected choices into the individual components and give you choices counts, making reporting easier.


Thank you lizb311
Never knew those options existed! I see now indeed that this enabled multiple tags in the variable. Do you have any suggestions on how to get counts for each tag?


Hester With that type of embedded data, I think Qualtrics should automatically give you counts for each tag in your Reports section! Just add a visualization to your report for a bar chart or simple table if there's not one for that embedded data field already. Very little heavy lifting for you there.
If you need to get counts outside of Qualtrics, then I like using Excel with

countifs()
formulas. Something like
=COUNTIFS(A1, "*First response option*")
would give you the count of people who put the text "First response option" in cell A1. You could also use table or column references instead of cell references, to get summary counts for all of your data instead of just a single respondent. Using the * before and after the text you're searching for ensures that Excel finds that phrase in each cell regardless of what text comes before or after the phrase - making it handy for your situation where multiple items can appear in the same cell.


The solution of multitext as variable type when setting the embedded data, and then viewing the count in report, and Stats iQ worked 🙏. Thank you so much lizb311! That saved me a lot of headaches!


Hester Great, I'm glad it worked for you! Good luck with the rest of your survey!
😄


Leave a Reply