How can I keep response from a randomized last question and add this within survey's final question? | XM Community
Skip to main content

Hello, I am trying to ask a question at the very end of the survey that needs to include the participant's answer to the last question shown (e.g., You said "[the participant's answer to the last question]". Why do you think so?). Yet, the question groups and the questions within blocks are randomized, so the last question is not fixed. I am looking for a solution to do this either with a code component or other options (piped text/embedding data, etc.).
Thank you!

https://community.qualtrics.com/XMcommunity/discussion/23576/how-can-i-keep-response-from-a-randomized-last-question-and-add-this-within-surveys-final-questionThis might be a bit manual and there could be an efficient way to do this.
Create embedded data and push all questions answer in it via JS (include same code on all questions or if one page per q include in header, on page submit). The last time that embedded data gets updated would be the last question of survey. Push that embedded data in end of the survey message.
Hope it helps!


Thank you for your answer Deepak!
Would you provide an example for that if possible: "Create embedded data and push all questions answer in it via JS -include same code on all questions-"?
For the second part (end of survey message): do you mean showing the question instead of a "thank you for participation" message?
Thank you!


https://community.qualtrics.com/XMcommunity/discussion/comment/54102#Comment_54102This link should help you in pushing the answers in embedded data
Using JavaScript with Embedded Data and/or selected choices. — XM Community (qualtrics.com)
The below link would give you an idea for creating custom end of survey message
Custom end of survey message — XM Community (qualtrics.com)
Hope it helps!


https://community.qualtrics.com/XMcommunity/discussion/comment/54105#Comment_54105https://community.qualtrics.com/XMcommunity/discussion/comment/54089#Comment_54089Thank you Deepak!
Here is what I have tried:
I added javascript code in each question in that way:
Qualtrics.SurveyEngine.addOnload(function()
{
var answer = "${e://Field/answer}";
Qualtrics.SurveyEngine.setEmbeddedData('answer', answer);
});
Qualtrics.SurveyEngine.addOnReady(function()
{
/*Place your JavaScript here to run when the page is fully displayed*/
});
Qualtrics.SurveyEngine.addOnUnload(function()
{
/*Place your JavaScript here to run when the page is unloaded*/
});

Then, I tried to pipe this in the end message:
image.pngHowever, it did not work:
image.pngWhat do you think I am missing here?
I also tried changing the location of the javascript (to OnReady), but it was not a solution.
Thanks a lot!


https://community.qualtrics.com/XMcommunity/discussion/comment/54114#Comment_54114The code is incorrect, you need to pipe the selected answers as value and not the embedded data. Also, you need to do it on page submit and not on load. https://api.qualtrics.com/ZG9jOjIwMTY2NzUy-javascript-question-api
Hope it helps!


https://community.qualtrics.com/XMcommunity/discussion/comment/54116#Comment_54116Hello again Deepak,
Here is the new approach I have tried according to what I understood from your answer but it did not work out:
I specified this for each question:
Qualtrics.SurveyEngine.addOnload(function()
{
/*Place your JavaScript here to run when the page loads*/
});
Qualtrics.SurveyEngine.addOnReady(function()
{
/*Place your JavaScript here to run when the page is fully displayed*/
});
Qualtrics.SurveyEngine.addOnUnload(function()
{
/*Place your JavaScript here to run when the page is unloaded*/
});
Qualtrics.SurveyEngine.addOnPageSubmit(function() 
{
  var answer= "${q://QID5/ChoiceGroup/SelectedChoices}";
});

And, I called the variable "answer in the piped text as such:
image.pngBut the result is:
image.png
How should I call this variable in the piped text?
Thanks a lot!


https://community.qualtrics.com/XMcommunity/discussion/comment/54151#Comment_54151You kept the value correct but you haven't pushed it in the answer embedded data which you're calling in end of survey message.include that line as well As you did before


https://community.qualtrics.com/XMcommunity/discussion/comment/54152#Comment_54152Thanks for your response Deepak!
Now, my code is like that (but it did not work out):
Qualtrics.SurveyEngine.addOnload(function()
{
/*Place your JavaScript here to run when the page loads*/
});
Qualtrics.SurveyEngine.addOnReady(function()
{
/*Place your JavaScript here to run when the page is fully displayed*/
});
Qualtrics.SurveyEngine.addOnUnload(function()
{
/*Place your JavaScript here to run when the page is unloaded*/
});
Qualtrics.SurveyEngine.addOnPageSubmit(function() 
{
  var answer= "${q://QID5/ChoiceGroup/SelectedChoices}";
Qualtrics.SurveyEngine.setEmbeddedData("answer", answer);
});

I kept the piped text as it is the last time:
image.pngIt did not work when it is ${e://Field/answer} in the end message editor, either.
Thanks a lot!


https://community.qualtrics.com/XMcommunity/discussion/comment/54156#Comment_54156Unfortunately, the value isn't getting captured on the same page. Hence, that code would have worked on next page. But that wouldn't solve your issue as it is randomized. My suggestion would be get selected choices and use variable naming for it to get actual value.
Hope it helps!


https://community.qualtrics.com/XMcommunity/discussion/comment/54162#Comment_54162This solution worked! Thank you so much Deepak!
Here is Deepak's javascript suggestion, if anyone else also needs it:
Qualtrics.SurveyEngine.addOnPageSubmit(function()
{
var x = this.getSelectedChoices();
var y = this.getChoiceVariableName(x);
Qualtrics.SurveyEngine.setEmbeddedData("y", y);
console.log(y)
});


Leave a Reply