E-mail Trigger Formatting: Replacing Comma with Line Break | XM Community
Skip to main content
Solved

E-mail Trigger Formatting: Replacing Comma with Line Break


rhonnied1
I have an e-mail trigger in which part of the piped text are multiple selections that have been chosen. In the e-mail, the selections appear straight across the screen, separated by commas. This is unattractive, and I would like for each of the selections to appear on a new line. How can I do this?

Best answer by TomG

Replace the commas with breaks and save to an embedded variable. Then pipe the embedded variable into your email trigger. ``` Qualtrics.SurveyEngine.setEmbeddedData("myVar", "${q://QID1/ChoiceGroup/SelectedChoices}".replace(/, /g, "<br>")); ```
View original

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • February 27, 2019
Replace the commas with breaks and save to an embedded variable. Then pipe the embedded variable into your email trigger. ``` Qualtrics.SurveyEngine.setEmbeddedData("myVar", "${q://QID1/ChoiceGroup/SelectedChoices}".replace(/, /g, "<br>")); ```

rhonnied1
@TomG I copied and pasted your code in the JS for the specific question (unless I was supposed to do it in the e-mail trigger itself). I set the variable (myVar) in the Survey Flow; then referenced it in the e-mail trigger: I got nothing.

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • February 27, 2019
> @rhonnied1 said: > @TomG > I copied and pasted your code in the JS for the specific question (unless I was supposed to do it in the e-mail trigger itself). > I set the variable (myVar) in the Survey Flow; then referenced it in the e-mail trigger: I got nothing. > The JS has to go in a question on a page after the question you are piping.

rhonnied1
@TomG IT WORKED!!!!! THANK YOU SO VERY MUCH! This is a game-changer!

Forum|alt.badge.img+4
Tom - or anyone else following this thread - I've tried to follow along and it seems fairly simple but I must be doing something wrong. I created the embedded data variable in survey flow at the beginning of the survey. Here is what I have for the javascript code on a question long after the one I'm trying to test out formatting (I put it on a question in a completely different block.) My variable just isn't getting populated upon submission :s `Qualtrics.SurveyEngine.addOnload(function() { Qualtrics.SurveyEngine.setEmbeddedData("64-1", "${q://QID2/ChoiceGroup/SelectedChoices}".replace(/, /g, "<br>")); }); Qualtrics.SurveyEngine.addOnReady(function() { /*Place your JavaScript here to run when the page is fully displayed*/ }); Qualtrics.SurveyEngine.addOnUnload(function() { /*Place your JavaScript here to run when the page is unloaded*/ });`

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • March 4, 2019
@jrkinsella, Check to make sure your pipe is correct. It is best to use "Piped text" to pipe it into the question text, then copy it to your JavaScript. If that isn't the problem, try renaming your variable with a letter. I don't know that you can't use just numbers, but most platforms don't like it, so I never do it.

  • December 19, 2019
> @TomG said: > Replace the commas with breaks and save to an embedded variable. Then pipe the embedded variable into your email trigger. > ``` > Qualtrics.SurveyEngine.setEmbeddedData("myVar", "${q://QID1/ChoiceGroup/SelectedChoices}".replace(/, /g, "<br>")); > ``` Hi @TomG , Can you clarify what you mean by "replace the commas with breaks and save to an embedded variable"? What do I set the variable "myvar" in the survey flow as? For ex, in the survey flow do I put myVar = ${q://QID1/ChoiceGroup/Displayedchoices}".replace(/, /g, "<br>" as an embedded field? I have a similar issue except that I would like the "displayed choices" from a MC question to appear on the email trigger without commas.

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • December 19, 2019
> @Thebika said: > > @TomG said: > > Replace the commas with breaks and save to an embedded variable. Then pipe the embedded variable into your email trigger. > > ``` > > Qualtrics.SurveyEngine.setEmbeddedData("myVar", "${q://QID1/ChoiceGroup/SelectedChoices}".replace(/, /g, "<br>")); > > ``` > > Hi @TomG , > > Can you clarify what you mean by "replace the commas with breaks and save to an embedded variable"? What do I set the variable "myvar" in the survey flow as? > > For ex, in the survey flow do I put > myVar = ${q://QID1/ChoiceGroup/Displayedchoices}".replace(/, /g, "<br>" as an embedded field? > > I have a similar issue except that I would like the "displayed choices" from a MC question to appear on the email trigger without commas. @Thebika, You have to do it in JavaScript. Add the JavaScript to a question on a page after the MC question you want to pipe the answer to. Define "myvar" embedded data field at the top of the survey flow. No need to assign a value to it.

  • December 20, 2019
Hi @TomG, Thank you for your response. I did the following: 1) Inputted "myvar" into the survey flow as an embedded data field. 2) Pasted the javascript below in a question that is in the same block and after the MC question ! However, it did not work. Do I have to input a page break between the two questions? I should also note that all my questions in the block have a display logic on them, including the MC question. Also, I did not pipe anything into the email message (which has been created as a task in "Actions")

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • December 20, 2019
> @Thebika said: > Hi @TomG, > > Thank you for your response. > > I did the following: > 1) Inputted "myvar" into the survey flow as an embedded data field. > 2) Pasted the javascript below in a question that is in the same block and after the MC question > > ! > > However, it did not work. > > Do I have to input a page break between the two questions? > > I should also note that all my questions in the block have a display logic on them, including the MC question. Also, I did not pipe anything into the email message (which has been created as a task in "Actions") 1. Is the JS line inside the addOnload or addOnReady function? If not, it needs to be. 2. Yes, you need a page break between the MC and the question with the JS. 3. You need to pipe myvar into the Email Action.

  • January 5, 2020
This solution looks very promising for us, but my multi-selection question is the final one of the survey. Is there an alternative solution in this case, as I don't have a subsequent question to add the javascript code? Thanks!

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • January 5, 2020
> @KellyT said: > This solution looks very promising for us, but my multi-selection question is the final one of the survey. Is there an alternative solution in this case, as I don't have a subsequent question to add the javascript code? The easiest solution is to add a descriptive text question to the next page, attach the JS to it, and have the JS click the next button.

  • January 5, 2020
> @TomG said: > > @KellyT said: > > This solution looks very promising for us, but my multi-selection question is the final one of the survey. Is there an alternative solution in this case, as I don't have a subsequent question to add the javascript code? > The easiest solution is to add a descriptive text question to the next page, attach the JS to it, and have the JS click the next button. > > Thank you! The entire solution is working for me now.

Leave a Reply