Hide and prefill a question value | XM Community
Skip to main content

Hello to everyone in this awesome community!
I was investigating a business requirement for one of my surveys and I wanted to ask the community's opinion on the matter.
What I want to accomplish is: If a user changes the Survey Language to e.g. "Swedish", the I want to hide the "Country" question and prefill it with the value "Sweden". I have already managed to hide the Question with a condition but I haven't found a good solution to prefill the value to Sweden.
Straight forwards solutions I found so far include:
1. Use a question default value and set it to "Sweden"
--> a side effect here is that Sweden is preselected for all users, not only for the ones who selected Swedish for the survey language
2. Create a new embedded data field which will hold the Country name. The value of the field is set by "Branches", Sweden is set when the Swedish language is selected and a piped value of the Country dropdown selection is set otherwise.
--> a side effect here is that value of the Country field is sometimes translated to the corresponding language which was selected by the user: e.g. there are entries of both Germany and Deutchland.
Anyone here have a better idea for implementing this requirement? Preferably, a solution that doesn't have side effects.
Thank you all in advance!

Hi MDyDiana
what you could do is to add a javaScript to the country question
when Q_Language isn't equal to your standard question
then you could set the question according to the language using the function
this.setChoiceValueByRecodeValue()

for example:

let selectedLanguage = "${e://Field/Q_Language}"
if(selectedLanguage == "SE"){
this.setChoiceValueByRecodeValue(2,1) // 2 being the recode for Sweden in your country question
this.clickNextButton() // automatically click the next button
}else if(selectedLanguage == 'JA' ){
this.setChoiceValueByRecodeValue(5,1) // 5 being the recode for Japan in your country question
this.clickNextButton() // automatically click the next button
}
you could repeat the else-if-conditions for all languages for which you set the country by script. For the remaining languages, the question would be still displayed

Add your script to the OnLoad function

Best regards

Rudi


Thanks a lot for your input!
I'm gonna try it out, see how it looks! :)


Leave a Reply