left/right substring extraction functions from piped text? | XM Community
Skip to main content
Solved

left/right substring extraction functions from piped text?

  • December 30, 2018
  • 3 replies
  • 160 views

I have a drill-down question, the third tier of which is populated with choices that all follow the same format: "(9-digit ID) - (person's name)". I can base piped text off of this subquestion just fine, but I am looking to have a modified piped text to put into an embedded data field that only captures the first 9 characters of the string for any of the possible choices (i.e. I only want the ID to be piped into the embedded data field from the selected choice). Is there a way to mimic a LEFT(string, 9) function from excel in the survey flow to get that substring extracted correctly?

Best answer by fleb

You can do this using following JavaScript: Qualtrics.SurveyEngine.addOnload(function() { var a = "${q://QID28/ChoiceGroup/SelectedChoices}".substring(0,9); Qualtrics.SurveyEngine.setEmbeddedData("a", a); }) (I found that here.) Note: The code must be executed after submitting the page with the question. (You can do it earlier, but then you can't use piped text). Note 2: Your embedded data field must be defined in the survey flow.
View original

3 replies

fleb
Level 3 ●●●
Forum|alt.badge.img+6
  • Level 3 ●●●
  • 197 replies
  • Answer
  • January 2, 2019
You can do this using following JavaScript: Qualtrics.SurveyEngine.addOnload(function() { var a = "${q://QID28/ChoiceGroup/SelectedChoices}".substring(0,9); Qualtrics.SurveyEngine.setEmbeddedData("a", a); }) (I found that here.) Note: The code must be executed after submitting the page with the question. (You can do it earlier, but then you can't use piped text). Note 2: Your embedded data field must be defined in the survey flow.

@fleb thank you so much for your help, that worked beautifully!

fleb JonathonJames This is very useful for a workaround I'm trying to establish. I'm certainly not a JavaScript aficionado. Exactly how do I define the embedded data field? Currently my Survey Flow is question block with a select box > embedded data with a = a question block with piped text of embedded data field ${e://Field/a}
What have I got twisted around? All help is appreciated!


Leave a Reply