left/right substring extraction functions from piped text? | XM Community
Solved

left/right substring extraction functions from piped text?

  • 30 December 2018
  • 3 replies
  • 93 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?
icon

Best answer by fleb 2 January 2019, 18:27

View original

3 replies

Userlevel 5
Badge +6
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