Cumulative list of descriptive text questions shown | XM Community
Skip to main content

Hi Qualtrics users,
I'm working on a project with lots of branching, which will determine which descriptive text questions will be shown to each survey respondent. I'd like to help survey respondents keep track of the descriptive text they've read by including a summary page: however, I want this summary page to show only that descriptive text which that survey respondent has actually seen. (For example, choice 1 leads to either Text1 or no Text1, choice 2 leads to either Text2 or no Text2, choice 3 leads to either Text3 or no Text3. At the end, if the respondent chose text for Choice 1 and 3 but not for Choice 2, I want only Text1 and Text3 to show in the summary.)
I originally thought that Qualtrics already did this: that the survey would only show piped text if the respondent had viewed that text in the current survey. However, it seems I was wrong. I am therefore looking for some custom code alternatives.
Does anyone have any suggestions for how to approach this problem?
My current plan is to see if I can create an embedded data field for the summary, and update it to append the additional text items as they appear. I'm unsure whether I'll have control over formatting in this case (ideally, each Text should be its own list item or paragraph). I'm not an expert, so it'll take me some time to see if this works. Any guidance or helpful suggestions would be most appreciated. Thanks!

Add this JS to every question text that you want to collect.
I suggest initializing the variable

shown 
in the survey with a few spaces, otherwise you'll see a
null 
at beggining.
Qualtrics.SurveyEngine.addOnReady(function () {
    let shown = Qualtrics.SurveyEngine.getEmbeddedData("shown");
    let new_text = shown + "
" + this.getQuestionTextContainer().innerText;
    Qualtrics.SurveyEngine.setEmbeddedData("shown", new_text);
});
This only execute when the question is displayed, therefore it will only capture the relevant text. If you'd like to capture more than one text from the same page, then the logic will get a little complicated.


Thank you ahmedA!
Here is the final code I ended up with, in case anyone else has the same problem:
Qualtrics.SurveyEngine.addOnReady(function()
{
var OldSummary = "${e://Field/SummaryText}";
var NewText = this.getQuestionTextContainer().innerText;
var NewSummary = OldSummary + "
" + NewText;
Qualtrics.SurveyEngine.setEmbeddedData('SummaryText', NewSummary)    

var OldCount = parseInt("${e://Field/CountInq}");
var NewCount = OldCount+1;
Qualtrics.SurveyEngine.setEmbeddedData('CountInq', NewCount)    
});

The first part addresses the question I posted. Note that I needed to create an embedded data field named SummaryText in order for this to work. If you're working on a similar problem, know that you can also make the summary a bulleted list with a bit of additional HTML code.
The second part counts the number of times I added text to the summary. I needed to create an embedded data field named CountInq and set it to zero for this to work.


Leave a Reply