Can I set embedded data from variable names? | XM Community
Skip to main content

Hi all. I'm trying to set embedded data from a question that I have added variable naming to the responses. In short, I want to include the variable names as embedded data, not the values or the answer text because it has HTML encoded in it. Is this possible?
I thought I had set embedded data up this way by selecting "insert piped text - selected choices recode" which means in my survey flow the embedded data = ${q://QID2/SelectedChoicesRecode} But this just adds numbers to the embedded data which is worthless.
I've gone through my embedded data and it turns out this hasn't been working for a while when I'm sure I had it working a few months ago so I'm at a loss as to what to do.
Am I doing something wrong? Did Qualtrics change something? Is this a bug? Hope someone can help. Thanks :)

Amy_boz
Unfortunately you cannot pipe in the variable naming in the embedded data via piped text.
You can do this either via JS and set variable name as embedded data.
Or hardcode the option choices in embedded data and based on branch logic pipe that embedded data.
Hope it helps!


Thanks for responding. I wouldn't be able to use the Branch if in the survey flow because I have 14 options and it's a multiple choice... Would you happen to know where I can find the Java script to be able to do the other option?


Amy_boz
You can use something like this and repeat it for your 14 options and include in a variable comma-separated. There can be a better way but this worked for me. Kindly change the QID as per your question. This is similar to creating a branch logic based on choice recodes and set the logic based on contains, and using that value in an embedded data comma separated in survey flow.
Qualtrics.SurveyEngine.addOnPageSubmit(function()
{
const str = '${q://QID46/SelectedChoicesRecode}';
function containsNumbers(str) {
  return //0-9]/.test(str);
}
/*1*/
var a = containsNumbers("1");
if (a==true){
var b = this.getChoiceVariableName(1);
}
var value = (b);
console.log(b);
Qualtrics.SurveyEngine.setEmbeddedData( 'choice', value );


});


Hope it helps!


Amy_boz,
You can add this JS to your question:
Qualtrics.SurveyEngine.addOnPageSubmit(function() {
var qobj = this, vnames = [];
jQuery.each(qobj.getSelectedChoices(), function(i,val) {
vnames.push(qobj.getChoiceVariableName(val));
});
Qualtrics.SurveyEngine.setEmbeddedData("data",vnames.join(", ");
});


@TomG script above gives me an “unexpected token” error when trying to save the JS…  Any help greatly appreciated :-)


@TomG script above gives me an “unexpected token” error when trying to save the JS…  Any help greatly appreciated :-)

It was missing a ). Use this:

Qualtrics.SurveyEngine.addOnPageSubmit(function() {
var qobj = this, vnames = n];
jQuery.each(qobj.getSelectedChoices(), function(i,val) {
vnames.push(qobj.getChoiceVariableName(val));
});
Qualtrics.SurveyEngine.setEmbeddedData("data",vnames.join(", "));
});

 


@TomG  does if work for a multiple questions? it doesn’t return any results


@TomG  does if work for a multiple questions? it doesn’t return any results

I assume you mean multi-select multiple choice questions. Yes it works, but I’m not sure about Simple layout (haven’t tried it). I’m not sure what you mean by ‘it doesn’t return any results.’ You’d have to be more specific.


you are right @TomG  - doesn’t work in the “Simple layout” but it does work if I change to another one… interesting and a bit frustrating. Do you know how to use it in Simple layout? 


you are right @TomG  - doesn’t work in the “Simple layout” but it does work if I change to another one… interesting and a bit frustrating. Do you know how to use it in Simple layout? 

As I said, I haven’t tried it.  At a minimum, you would have to load jQuery, which isn’t loaded by default in Simple Layout, and you may need to use setEmbeddedJSData instead.


Leave a Reply