Need help with java to use embedded data to pre-fill multiple choice questions | XM Community
Skip to main content

Hi all -

Very thankful for this community as I am working to set up a survey that has a lot of answers pre-filled from previous responses. I’ve already found and successfully employed a javascript code to pre-select multiple choice question options based on embedded data; however, I am now not able to duplicate it for some reason.

The code I used was:


Qualtrics.SurveyEngine.addOnReady(function()
{
    if ("${e://Field/InvestorRole}".includes("Majority")) this.setChoiceValue(1, true);
    if ("${e://Field/InvestorRole}".includes("Minority")) this.setChoiceValue(2, true);
  

});

 

I think tried to use it for the next question, reolacing the items highlighted and adding rows as needed (and then, of course, going up in numbers on set choice value - 3, 4, etc.). Now… nothing. Any ideas? I’m very confused. I double checked embedded data was entered properly, no case differences, changes published, etc.

Sometimes the choice numbers can go out of hand.

You could try the following:

Add this before the if statements: const choices = this.getChoices();

Then you can select the appropriate choice by this.setChoiceValue(choicese0], true);  and so on.

 

Another possible issue could be if you are previewing the block, for ED to work, you need to preview the survey.


Thanks @ahmedA! That seems to have worked! Am I right in understanding the choice numbers do not restart at 1 for later questions, then? Just trying to understand what it means by “choice numbers getting out of hand.” Will this same code work for all 15 or so questions I need to use it on?

Really appreciate your help!

 


Also, does case matter?


Leave a Reply