Setting answers to (hidden) question based on embedded data field | XM Community
Skip to main content

I have a multi-county survey (~100 countries) where there are certain areas in the survey that needs to be changed depending on the embedded variable “country”.

For example, there is a welcome message which also contains the Name & Designation of the responsible person at local entity at end of the message (let’s call this “welcome_signature”). Instead of creating 100 different welcome messages, I am considering to create 1 hidden question with 100 answer options and set the answer of this hidden question based on the embedded field country. Then use this hidden question as a pipe-in text in the welcome message.

This is just 1 example, but there are few other areas where similar country specific changes are needed.

However, I want to avoid writing 100 branching conditions. What would be ideal is to use the country variable to directly assign the answer options of the hidden questions. (something like welcome_signature = country).

Not the best example, because it sounds like I could also use the translations to change the content to be country specific. But there are many such customizations (where I cannot use translations) and I would like to see if there is a programmatic solution available for my requirement.

How can I achieve this?

@Dhananjayan Palaniswamy Put this JS in your welcome question

Qualtrics.SurveyEngine.addOnload(function()
{
/*Place your JavaScript here to run when the page loads*/

var country="${e://Field/Country}";

if (country=="EN") {this.setChoiceValue(1,true) ; }
if (country=="FR") {this.setChoiceValue(2,true) ; }
if (country=="GER") {this.setChoiceValue(3,true) ; }
if (country=="CN") {this.setChoiceValue(4,true) ; }
if (country=="RUS") {this.setChoiceValue(5,true) ; }
var questionDiv = this.getQuestionContainer();
questionDiv.style.display = "none";
});

This code will set answer base on embbedded data “Country”, it will also hide your question with .style.display = “none”. Set other value according to yours.

 


Hi @Dhananjayan Palaniswamy ,

There is another , since you will be already using JS, then you can implement the above  using below method :

1)Create two embedded variables namely Q_Language and welMsg. 
 2)Now add below JS in the  question before where you will be sharing the the message :

Qualtrics.SurveyEngine.addOnload(function()
{
/*Place your JavaScript here to run when the page loads*/

});

Qualtrics.SurveyEngine.addOnReady(function()
{
let welCom="${e://Field/Q_Language}";
console.log(welCom);


if(welCom=="EN")//for US
{
Qualtrics.SurveyEngine.setEmbeddedData('welMsg', '<p>Thank you for participating in our survey. Your feedback is important to us and will help us improve our services.</p> <p>Please take your time to answer the questions thoughtfully and honestly. Your input is greatly appreciated.</p>');

}

if(welCom=="DE")//for Germany
{
Qualtrics.SurveyEngine.setEmbeddedData('welMsg', 'Custom message');

}

//and so on as many countries you wish to add





});

Qualtrics.SurveyEngine.addOnUnload(function()
{
/*Place your JavaScript here to run when the page is unloaded*/

});

In this context, the use of the "Q_Language" variable has been employed to optimize the country selection process. If desired, you may substitute "Q_Language" with a variable of your preference to achieve the same outcome.

Additionally , replace the welMSg  with message of your choice.

Hope it resolves your query 😊


@Dhananjayan Palaniswamy Put this JS in your welcome question

Qualtrics.SurveyEngine.addOnload(function()
{
/*Place your JavaScript here to run when the page loads*/

var country="${e://Field/Country}";

if (country=="EN") {this.setChoiceValue(1,true) ; }
if (country=="FR") {this.setChoiceValue(2,true) ; }
if (country=="GER") {this.setChoiceValue(3,true) ; }
if (country=="CN") {this.setChoiceValue(4,true) ; }
if (country=="RUS") {this.setChoiceValue(5,true) ; }
var questionDiv = this.getQuestionContainer();
questionDiv.style.display = "none";
});

This code will set answer base on embbedded data “Country”, it will also hide your question with .style.display = “none”. Set other value according to yours.

 

@dxconnamnguyen  This solution works almost perfectly for my requirement. Thanks to you!
However, there is a little problem. I am piping in this Hidden Dummy Question in the welcome message which is the first screen of the survey. So the answers are not showing up as a pipe-in. However, if I pipe-in this dummy question in the second page, it works. Now that the Hidden dummy question and the welcome message are on same page, the pipe-in doesn’t work. Any solution for this you would recommend?


@Dhananjayan Palaniswamy Put this JS in your welcome question

Qualtrics.SurveyEngine.addOnload(function()
{
/*Place your JavaScript here to run when the page loads*/

var country="${e://Field/Country}";

if (country=="EN") {this.setChoiceValue(1,true) ; }
if (country=="FR") {this.setChoiceValue(2,true) ; }
if (country=="GER") {this.setChoiceValue(3,true) ; }
if (country=="CN") {this.setChoiceValue(4,true) ; }
if (country=="RUS") {this.setChoiceValue(5,true) ; }
var questionDiv = this.getQuestionContainer();
questionDiv.style.display = "none";
});

This code will set answer base on embbedded data “Country”, it will also hide your question with .style.display = “none”. Set other value according to yours.

 

@dxconnamnguyen  This solution works almost perfectly for my requirement. Thanks to you!
However, there is a little problem. I am piping in this Hidden Dummy Question in the welcome message which is the first screen of the survey. So the answers are not showing up as a pipe-in. However, if I pipe-in this dummy question in the second page, it works. Now that the Hidden dummy question and the welcome message are on same page, the pipe-in doesn’t work. Any solution for this you would recommend?

@Dhananjayan Palaniswamy Then it should be update straight to the HTML, the pipe-text option is a bit unsuitable now.


Alternatively I tried to put the hidden dummy questions in a separate page and moved it ahead of the actual first screen the customers would see, and added a script “this.clickNextButton();” to the hidden question to auto advance the next screen. The only catch is that you can see the empty page for a second before it auto advances to the next screen with the actual welcome message.

 

Btw how do I update this straight to the HTML? Thanks in advance!


Btw how do I update this straight to the HTML? Thanks in advance!

You can set up a <div id="welcome">Welcome</div> in your HTML source

And then use script to update it directly like:

var mess;

if (country=="EN") {mess = this.getQuestionInfo().Choicese1].Text;}

var wcmess = document.getElementById("welcome");

wcmess.innerHTML = mess;


Leave a Reply