Set embedded data: Counting the number of words selected in a Highlight Question | XM Community
Skip to main content

Hi community,
I have a Highlight Question with a paragraph of text. There's only 1 category: "Contains a G." I ask participants to highlight all of the words that contain a G.
How do I set embedded data representing the number of words that they highlighted?
I want to tell participants in the next block, "You selected ${e://Field/num_gs_highlighted} words that round." I can't find anything in Scoring, unfortunately.
Thanks, as always!

A clue:
I can set embedded data (e.g.,

highlighted_string
) that captures all of the words a person highlighted (e.g.,
highlighted_string
would be "3: Dogs, 5: Pickles").

Anyone know how to find the length (i.e., number of words) in an embedded data (in the above case, this would be 2 since "Dogs" and "Pickles" are the only two words?


This was solved on a different thread by GrumpyCivet. The solution here involves to steps:

  1. Create an embedded data field that captures the selected words from the Highlight question.

  2. Use JavaScript in a subsequent question to count the length of that embedded data field (by counting the number of commas).

How to do this:
  1. In the survey flow, set embedded data from the selected choices of the Highlight question. For instance, set
    high_string
    to ${q://QIDXXXXX/ChoiceGroup/SelectedChoices}

  2. Also in your survey flow, create an additional embedded data field (e.g., called
    word_count
    ) before the block that contains the Highlight question. Then, implement this solution is from GrumpyCivet HERE: In a later question, embed the following JS:

var myString = Qualtrics.SurveyEngine.getEmbeddedData("high_string");

var wordCount =0;

wordCount = myString.trim().split(',').length;

Qualtrics.SurveyEngine.setEmbeddedData("word_count", wordCount);
Voila! Thanks to GrumpyCivet for solving this one!


wscampbell, would this solution work on UnselectedChoices?


Having not tried this myself, I suspect it should work. Just set the embedded data to the UnselectedChoices.


Leave a Reply