Replacing comma with line break in piped text | XM Community
Question

Replacing comma with line break in piped text

  • 13 November 2020
  • 3 replies
  • 142 views

Badge +3

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! :)


3 replies

Userlevel 7
Badge +21

In JS, import the piped text and then replace the

comma 
with the line break tag


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

Badge +3

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 = "
"

  for(var i = 0; 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 = "
"

  for(var i = 0; i    var temp = textElements[i].innerHTML;
    console.log(temp);
    temp = temp.replace(new RegExp(", ", 'g'), newDelimiter);
    console.log(temp);
    textElements[i].innerHTML = temp;
}
});

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

Leave a Reply