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.

Replacing comma with line break in piped text

BarbiUF
BarbiUF FL, USA Qubie ✭
edited July 30 in Custom Code

Good afternoon. I'm trying to replace the usual comma with line breaks after each selection (piped in text using show selected) in a trigger email. I've tried a couple of different things but that just led me to realize I need to get some coding classes under my belt ASAP. Here is what I'm working with:

  • You will be assessing students’ performance on the following outcome(s):
  • ${q://QID18/ChoiceGroup/SelectedChoices}

They show up in the email like this:

You will be assessing students’ performance on the following outcome(s):

  • Outcome 6: Experiments, Outcome 7: New knowledge

What can I add to the piped text to make that comma a line break so they show one right under the other - like this:

You will be assessing students’ performance on the following outcome(s):

  • Outcome 6: Experiments
  • Outcome 7: New knowledge

Any help would be greatly appreciated. Any recommendations on coding courses to start with would be appreciated too! :)

Answers

  • ahmedA
    ahmedA India Wizard ✭✭✭✭✭
    edited December 2020

    In JS, import the piped text and then replace the comma with the line break tag <br>

    Then store it back to an embedded variable and use this variable instead of answer choices.

  • BarbiUF
    BarbiUF FL, USA Qubie ✭

    @ahmedA Would you mind showing me what that would look like? I've never used this before. I was trying to use the javascript option by entering this but it doesn't work. I'm pulling in the string of student data (last name, first name, email that sort of thing)

    Qualtrics.SurveyEngine.addOnReady(function()

    {

    var textElements = this.questionContainer.select('.CommaReplacement');  

      var newDelimiter = "<br>"


      for(var i = 0; i<textElements.length; i++){

        var temp = textElements[i].innerHTML;

        console.log(temp);

        temp = temp.replace(new RegExp(", ", 'g'), newDelimiter);

        console.log(temp);

        textElements[i].innerHTML = temp;

    }

    });


    Qualtrics.SurveyEngine.addOnUnload(function()

    {

    var textElements = this.questionContainer.select('.CommaReplacement');  

      var newDelimiter = "<br>"


      for(var i = 0; i<textElements.length; i++){

        var temp = textElements[i].innerHTML;

        console.log(temp);

        temp = temp.replace(new RegExp(", ", 'g'), newDelimiter);

        console.log(temp);

        textElements[i].innerHTML = temp;

    }

    });

  • Diwere
    Diwere Massachusetts Qubie ✭

    @BarbiUF - I'm having a similar issue. Would you mind sharing what you did to solve this problem?