Adding values to checklist from JSON. | XM Community
Skip to main content

I have a project letting teachers indicate who is still taking a class after add-drop. Rather than have the teacher type out which people have dropped the class, the idea is to list the roster as checklist and let teachers indicate which students are no longer attending by interacting with the form.
The roster is sent dynamically via JSON using a webservice call. I'm using JS to parse it into an array, and can add the items to the checklist, but the items do not register when clicked.
So, my questions:

  1. Is what I'm trying even possible? Is there another way I'm not seeing?

  2. If it is, what in my condensed code isn't working?

Condensed code: (The HTML code for the checkbox is copied from an existing option; checkboxNumber is used to indicate if this is the 2nd, 3rd, etc. option we're inserting.)
var checkboxCode = "[HTML code for checklist item]";
var mainList = document.getElementsByClassName('ChoiceStructure')[0];
mainList.innerHTML += checkboxCode;

// Add the new choices to the choices array.
var thisBlockChoices = Qualtrics.SurveyEngine.QuestionInfo[thisQuestionId]['Choices'];
var thisCourseChoices = { 'Exclusive': false, 'RecodeValue': checkboxNumber, 'VariableName': checkboxNumber, 'Text': checkboxText};
thisBlockChoices[checkboxNumber] = thisCourseChoices;
This seems to work on the console, but clicking added items gets the following error: "
Missing bound path:  runtime.Choices.2.Selected
". The runtime doesn't seem to see the added options, no matter what I do.
Thank you in advance for your help!

Hey ssplinter, just looking at your code. Unless you're setting thisQuestionId earlier in the code and omitted that from the snippet above, you're missing a period when setting thisBlockChoices (should be this.questionId, lower case 'q' if you're using the Qualtircs question API). If you're setting thisQuestionId as a variable earlier in the script, please disregard.

Also, I didn't have any luck setting thisBlockChoices with that line using square brackets. Side note: Qualtrics.SurveyEngine.QuestionInfo will grab all questionInfo for all questions on a page. Is that what you're after vs using getchoices() or getchoiceValue()?


Thanks for your reply, Jeremey!
Yes, I've set thisQuestionId earlier in the code. I am also able to set thisBlockChoices using the code above. 'Choices' is an array of objects, numbered sequentially; I'm adding to that array. It updates fine, but doesn't seem to update whatever object Qualtrics is using to determine valid checkbox elements.
As I understand it, Qualtrics.SurveyEngine.QuestionInfo[thisQuestionId] will select only the question that matches that question id. The QualtricsAPI page doesn't list any methods for adding choices; is there a method I'm missing?


I confess I do not know how Qualtrics handles it's answers to that depth. Would be great to understand though! The survey must be watching something (an element or otherwise) that it saves to the data set upon submission, but I'm not sure how to even go about monitoring that.. I'll give it some more thought and let you know if I come up with something.


Thank you, Jeremy! At the very least, you've confirmed I'm not insane.
And if Qualtrics is listening, the ability to dynamically populate these kinds of fields with webservice data would be a tremendous help for cases like this. You give us a format, we'll make sure our data matches it!


Leave a Reply