How do I use JavaScript to create embedded data from a previous answer? | XM Community
Skip to main content

I am having trouble taking the answer from a previous question and using those values in the following question text. So far, I have been able to use jQuery successfully to display all of the necessary information. However, I was unable to find a way to format the text when using this method (bolding text, line breaks, etc.) making it very difficult to read as the user due to all of the text being on a single line. Thus, I have moved to the method of embedded data as that appeared to be easier to format. As an example, I have used the following lines of code to set the value for the embedded data after gathering the information from the written response OnUnload of the first question.

Qualtrics.SurveyEngine.setEmbeddedData("Last Name",dlLastName);
Qualtrics.SurveyEngine.setEmbeddedData("First Name",dlFirstName);

This code is present in the first question and I have set the embedded data in the Survey Flow window (without any assigned values). Whenever, I use the piped text feature in the embedded data shows up as an option, but, when ran, the values of the embedded data are either null or do not display when moving to the second question where they should be present. I am not sure which is the true case. Any help would be appreciated and I would be glad to provide more information or screenshots if necessary. Thanks!

I am having trouble taking the answer from a previous question and using those values in the following question text. So far, I have been able to use jQuery successfully to display all of the necessary information. However, I was unable to find a way to format the text when using this method (bolding text, line breaks, etc.) making it very difficult to read as the user due to all of the text being on a single line. Thus, I have moved to the method of embedded data as that appeared to be easier to format. As an example, I have used the following lines of code to set the value for the embedded data after gathering the information from the written response OnUnload of the first question.

Qualtrics.SurveyEngine.setEmbeddedData("Last Name",dlLastName);
Qualtrics.SurveyEngine.setEmbeddedData("First Name",dlFirstName);

This code is present in the first question and I have set the embedded data in the Survey Flow window (without any assigned values). Whenever, I use the piped text feature in the embedded data shows up as an option, but, when ran, the values of the embedded data are either null or do not display when moving to the second question where they should be present. I am not sure which is the true case. Any help would be appreciated and I would be glad to provide more information or screenshots if necessary. Thanks!

Hi, mind if i ask why are you using jquery and not the pipedtext option directly to push answer from previous question to next question? are the questions on the same page without a pagebreak? 


Hi, thank you for the response and I apologize for the confusion in my post, I am no longer using jQuery as part of my code and am attempting to only use embedded data and the pipedtext option as you suggested. However, when using the pipedtext none of the values are being displayed within the second question. The questions are on separate pages and use a pagebreak.


No problem, meant to ask why aren’t you just adding a selected answer pipe text directly in the question. Like the below image

 

But just incase you want to use an embedded data to save the selected answer and then pass the answer to the other question, the questions need to be in different blocks and the embedded data needs to be between the two blocks in the survey flow. because the questions are one after the other the answer isnt being saved in the embedded data before going to the second question


I believe I am unable to do that because the question I am asking is an essay response. the following code is all present within question 1.

For better context, the first question is the result of the scan of a barcode and I used JavaScript Regex features in order to collect the information I need. The second question is meant to display this information and then have the user confirm whether it is accurate or not. I also have the embedded data set between the two blocks in the survey flow so that should be correct.


Leave a Reply