Community Groups are officially here!
We've released Groups, a new feature that enables us to connect community members of similar industries and interests in a shared, private space. You can check out all of the details here, including information about who can join, how to join, and what Groups are currently offered. Please leave your feedback through this Community Groups Feedback Survey.

left/right substring extraction functions from piped text?

JonathonJames
JonathonJames San AntonioCommunity Member, Qualtrics Brand Admin Qubie ✭
edited June 23 in Survey Platform

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

  • fleb
    fleb Czech RepublicCommunity Member Sage ✭✭✭
    Accepted Answer

    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.

Answers

  • JonathonJames
    JonathonJames San AntonioCommunity Member, Qualtrics Brand Admin Qubie ✭

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

  • Anthony_Held
    Anthony_Held Columbia, MOCommunity Member Qubie ✭

    @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!