Is it possible to pull embedded data into a drop down selection to autofill the choice? | XM Community
Skip to main content

Sorry this question may be ambiguously phrased. Essentially I have a COVID vulnerability questionnaire that adds a participants "Actual" age to a set of scored health conditions and churns out a combined age which then determines if a person should or shouldn't return to work.
My issue is the recent medical guidelines have changed from a generic "if you have mild asthma add 2 years to your age" to "if you have mild asthma and you are 20 add 23 years, 21 add 23 years- 75 add 1 year". The scoring is not linear or simple as it was when I first generated the survey. So I have edited the survey to include display logic for each health condition, and a drop down age selection box if they select yes to that condition. Each age drop down is scored according to the medical guidelines. The problem is for each medical condition participants say they have, they then need to select their age. Is there a way I can autofill the drop down from their actual age (which is set up as embedded data) so if they select yes I have this condition, their age is already selected and they click continue.
I've tried setting this up with Carry forward choices but this doesn't work. Presumably I can set this up using Javascript, but I have no idea how to script it? Can anyone help?

After the age and medical health question, create an embedded data setting the appropriate formula to add age based on condition. Then display this embedded data in the option list of your dropdown question.


I know this is an old post but I have a similar question. Our client is providing 3 embedded data values which they would like us to pull through to show as the default choice in a dropdown question. They want the customer to be able to change the dropdown if the data pulled through is incorrect but they want it to at least default the choice to what the data value is. 


Hi , Just wanted to know if you were able to autofill the dropdown. I have similar question that I need to auto fill the dropdown based on th embedded data.


You can do this with JavaScript. For example, if you have an age question and recode the choices to actual ages (e.g., if someone picks “21 years old” the recode value will be 21), then this JavaScript will select the choice that matches the embedded data field age:

Qualtrics.SurveyEngine.addOnload(function() {
this.setChoiceValueByRecodeValue("${e://Field/age}",true);
});

 

 


You can do this with JavaScript. For example, if you have an age question and recode the choices to actual ages (e.g., if someone picks “21 years old” the recode value will be 21), then this JavaScript will select the choice that matches the embedded data field age:

Qualtrics.SurveyEngine.addOnload(function() {
this.setChoiceValueByRecodeValue("${e://Field/age}",true);
});

Hi Tom , Thanks fo the reply . I just want to know the code you have provided is this "${e://Field/age}" the syntax for fetching embedded data .

My use csae is , i am basically fetching the value from query param and setting it to embeeded data and then will be using the value to autofill themdrpdown question.

 

 


@Sura,

Yes, you can pipe your embedded data field directly into a JavaScript string. In my example the embedded data field name is age, so it is piped as ${e://Field/age}.


@TomG , can you accomplish the same thing using the Piped Text option in the Question Block or is field solution and/or JS code solution more dynamic/flexible? I haven’t stress tested the system or changed stuff since we set up similar questions. I’m jsut curious about choosing these approaches over the OoB setup


@TomG , can you accomplish the same thing using the Piped Text option in the Question Block or is field solution and/or JS code solution more dynamic/flexible? I haven’t stress tested the system or changed stuff since we set up similar questions. I’m jsut curious about choosing these approaches over the OoB setup

There is no way to select a drop-down choice to match a dynamic value without using JavaScript.


@TomG , can you accomplish the same thing using the Piped Text option in the Question Block or is field solution and/or JS code solution more dynamic/flexible? I haven’t stress tested the system or changed stuff since we set up similar questions. I’m jsut curious about choosing these approaches over the OoB setup

There is no way to select a drop-down choice to match a dynamic value without using JavaScript.

That is helpful to know. Thank you for the clarification. 


@Sura,

Yes, you can pipe your embedded data field directly into a JavaScript string. In my example the embedded data field name is age, so it is piped as ${e://Field/age}.

@TomG  Thanks for reply.

I have tried the method you have suggested . But , Still it doesn’t seem to work. To give you a quick back drop I am using multiple choice question type and Answer one answer type . Which is in dropdown. I am trying to pick the embedded data to be dispalyed as auto selected value in the dropdown when survey is displayed.  Could you suggest me a solution ? Thanks


@Sura,

It works for me. Not being able to see it, my best guess is that the value of your embedded data field isn’t a valid recode value for the question.

If recodes don’t work for you, a similar function using variable names is setChoiceValueByVariableName().


Leave a Reply