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

Prepopulate multiple choices with embed data

  • February 12, 2023
  • 5 replies
  • 117 views

Forum|alt.badge.img+1

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?

5 replies

Forum|alt.badge.img+1
  • Author
  • February 12, 2023

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


TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • February 12, 2023

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.


Forum|alt.badge.img+1
  • Author
  • February 12, 2023

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!!


TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • February 13, 2023

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); });


Forum|alt.badge.img+1
  • Author
  • February 13, 2023

TomG , you are THE man!