Prepopulate multiple choices with embed data | XM Community
Skip to main content

I am a new in Qualtrics and certainly appreciate your help here. I am building a survey with multiple choice question:
Please select equipment:
1) Freezer
2) File Cabinet
I was able to store the response(s) in Contact List in the field called "Equipment". I can see that values are being stored in the List as comma separated values. But when I am trying to retrieve the value using a Java script:
var answer = "${e://Field/Equipment}";
this.setChoiceValueByRecodeValue(answer, true);
but this does not work and value comes as empty. Can anyone help?

TomG , I know you are expert in this space, can you help?


Are the values stored as recodes (I.e., “1, 2”) in the contact list?
You need to parse the comma separated string and loop through the result to set each recode individually.


They are stored as comma separated values as string. I figured out a stupid way of doing it it works but it will be lot of repeated if statements. Looking for elegant way of doing it like you said.
var qobj = this;
var recodes = "${e://Field/Equipment}";
/*alert(" The value of Equipment is " + recodes);*/

if(recodes.includes("Freezer")) {
this.setChoiceValue(1, true);
}
if(recodes.includes("File Cabinet")) {
this.setChoiceValue(2, true);
}
I did not like the above code as each If statement executes here but works!!


https://community.qualtrics.com/XMcommunity/discussion/comment/55342#Comment_55342How about this:
var ids = {
"Freezer": 1,
"File Cabinet": 2
};
var qobj = this;
jQuery.each("${e://Field/Equipment}".split(", "),function(i,val){ qobj.setChoiceValue(ids[val],true); });


TomG , you are THE man!


Leave a Reply