Fetch response from one question and set the value in Embedded Data field | XM Community
Solved

Fetch response from one question and set the value in Embedded Data field

  • 26 August 2020
  • 6 replies
  • 308 views

Badge

Hi Everyone,

I have a single answer choice question Q4 in survey and I want to store some xyz value in the Embedded data field depending upon the choice selected in Q4. After that, I am using the Embedded data as a pipe text in the next question Q5.
Q4 and Q5 both questions are in separate blocks. Firstly, I tried doing this through branch logic in survey flow but the problem I am facing is the Back button gets disabled from the page when we use branch logic between the elements or blocks.
Client wants the Back button to be enabled so we are thinking if this can be achieved through custom javascript. I tried below code through which I am able to retrieve the alert box on Q4 showing the value selected but it is not setting the value in the embedded data. Name of the embedded data is Q5 CES Text.
Any help will be appreciated!
Code Below:
var selectedRecode; 
    this.questionclick = function(event, element) {
      if(element.type == "radio")
        {selectedRecode = Number(this.getChoiceRecodeValue(this.getSelectedChoices()));
          alert(selectedRecode);
if (selectedRecode == 1)
{
Qualtrics.SurveyEngine.setEmbeddedData('Q5 CES Text', test1);
alert(selectedRecode);
}
        }}

icon

Best answer by rondev 26 August 2020, 16:33

View original

6 replies

Userlevel 7
Badge +22

Have you created the embedded data - Q5 CES Text , in the survey flow before Q4?

Badge

yes, it looks like this on top of the survey flow
image.png

Userlevel 7
Badge +22

And you are setting 'test1' variable but you are not declaring or assigning anything to test1 as below:
var test1 = selectedRecode;

Badge

The requirement is to store the value test1 in the embedded data which is Q5 CES Text. I found the below syntax to store the value in ED which I have used in the code.
Qualtrics.SurveyEngine.setEmbeddedData('Q5 CES Text', test1);
Reference Page Screenshot:
image.png

Userlevel 7
Badge +22

If you want to store "test1" in embedded data then the code will be as below:
Qualtrics.SurveyEngine.setEmbeddedData('Q5 CES Text', "test1");
Also, just change the name of embedded data, as it is not in best practises to have spaces in embedded data name.

Badge

Thank you so much. This has helped me to store the value correctly in ED.
Unfortunately, this has not fully resolved the issue:
So I am having a following script now, for example:
var q4 = "${q://QID4/ChoiceGroup/SelectedChoices}";
if (q4 == "Explore destinations / get holiday ideas" || q4 == "Ziele erkunden und Urlaubsideen erhalten"){
Qualtrics.SurveyEngine.setEmbeddedData('Q5CESText', "1");
}
else if (q4 == "Search for a trip"){
Qualtrics.SurveyEngine.setEmbeddedData('Q5CESText', "2");
}
else if (q4 == "Make a booking today"){
Qualtrics.SurveyEngine.setEmbeddedData('Q5CESText', "3");
}
else if (q4 == "Manage my current booking"){
Qualtrics.SurveyEngine.setEmbeddedData('Q5CESText', "4");
}
else if (q4 == "Manage seat reservation / online check-in"){
Qualtrics.SurveyEngine.setEmbeddedData('Q5CESText', "5");
}
else {
Qualtrics.SurveyEngine.setEmbeddedData('Q5CESText', "6");
}
If I place this code in the addOnUnload section of javascript in Q4, it always shows the value 6 of else statement getting executed and appearing in Q5.
I have the question the ED placed as an piped text in Q5 which is just after Q4 in separate block.
I tried creating a separate metainfo and a timing question between Q4 & Q5, and putting the JS code on a metainfo but it doesn't work on both the questions
When I changed the metainfo to any text or multichoice question, and place JS code in addOnload section, then the code works perfectly fine.
Is there any possibility that the code runs and the value gets populated in ED without adding any extra question between Q4 & Q5 (still metainfo and timing question works which is not displayed to recipient).
Thank you so much once again for your inputs. Really appreciated.

Leave a Reply