preserving multi-line formatting of piped text in triggered emails | XM Community
Skip to main content
I am using Qualtrics to create online forms. I my forms, I have some "Essay Text Box" entries (or "Multi line").



I am using email triggers to deliver form replies via email and include those "Essay Text Box" entries into email body as piped text ${q://QID16/ChoiceTextEntryValue}.



Unfortunately, the new lines formatting from the original text is not preserved.



For example, if "Essay Text Box" entry was typed with multiple lines as:

_I want

this text

to be readable_



then, in emailed message it becomes just one line:

_I want this text to be readable_



Is there a way to preserve the original lines (new line) formatting?



I also insert piped text into "From Name:" and "Reply-To Email:" of emal triggers, which works well. Such feature seems to be not available in email Tasks. For that reason, I am not able to use Tasks instead of email triggers.



Thanks
You can use JavaScript to add html breaks to the piped text and save it to an embedded variable. Then pipe the embedded variable into your email trigger.

```

Qualtrics.SurveyEngine.addOnPageSubmit(function() {

var pipedText = jQuery("#"+this.questionId+" .InputText").val().trim().replace(/\\n/g, "<br>");

Qualtrics.SurveyEngine.setEmbeddedData("QID16pipedText", pipedText);

});

```
TomG,

I got the idea, but not sure about implementation details .



Just to be specific: I have question shown as "Q31"

if I wanted to insert the piped text from that question, it would be ${q://QID64/ChoiceTextEntryValue}. And the number 64 does not match the question number 31.



In your example, naming notion "QID16pipedText" is just for for the sake of explanation or it should match the question number or something?



In your code, I changed your "QID16pipedText" to "QID64pipedText" and inserted the code into Q31, 3 tmes:

/*Place your JavaScript here to run when the page loads*/

/*Place your JavaScript here to run when the page is fully displayed*/

/*Place your JavaScript here to run when the page is unloaded*/



Then, in my email trigger, I tried to put

${q://QID64pipedText/ChoiceTextEntryValue}

${q://QID64pipedText/pipedText}

${QID64pipedText}

${q://QID64/ChoiceTextEntryValue}

$pipedText}

${q://QID64/pipedText}

${QID64pipedText/pipedText}



It did not work.

What I m doing wrong?



BTW, I have more than one question with "Essay Text" entry.



Thanks.
> @Alex_WLU said:

> In your example, naming notion "QID16pipedText" is just for for the sake of explanation or it should match the question number or something?

You can name it whatever you want. I used QID16 because that's the question you referred to in your original question.



> In your code, I changed your "QID16pipedText" to "QID64pipedText" and inserted the code into Q31, 3 tmes:

> /*Place your JavaScript here to run when the page loads*/

> /*Place your JavaScript here to run when the page is fully displayed*/

> /*Place your JavaScript here to run when the page is unloaded*/

>

> Then, in my email trigger, I tried to put

> ${q://QID64pipedText/ChoiceTextEntryValue}

> ${q://QID64pipedText/pipedText}

> ${QID64pipedText}

> ${q://QID64/ChoiceTextEntryValue}

> $pipedText}

> ${q://QID64/pipedText}

> ${QID64pipedText/pipedText}



You only need the code once. Replace everything on JavaScript page with the code I provided. Let's say the embedded variable is myVar. Then you would pipe it into your email trigger as:

```

${e://Field/myVar}

```
If a web link copy-pasted into the box, then

it is distorted with some symbol replaced by %, etc.



How to preserve URL links?



Thanks.





> @TomG said:

> You can use JavaScript to add html breaks to the piped text and save it to an embedded variable.

> ```

> Qualtrics.SurveyEngine.addOnPageSubmit(function() {

> var pipedText = jQuery("#"+this.questionId+" .InputText").val().trim().replace(/\\n/g, "<br>");

> Qualtrics.SurveyEngine.setEmbeddedData("QID16pipedText", pipedText);

> });

> ```
> @Alex_WLU said:

> If a web link copy-pasted into the box, then

> it is distorted with some symbol replaced by %, etc.

>

> How to preserve URL links?

It sounds like it is being url encoded. It doesn't happen when I try it so it may be the way you are copying/pasting or where you are copying/pasting from. Anyway, you could decode it with either with unescape or decodeURIComponent.
> > you could decode it with either with unescape

>> or decodeURIComponent.

>

Will unescape and decodeURIComponent preserve multiple-line formatting?
@TomG

I've been trying to get this solution to work without luck.



Here's a screenshot showing the JS in the form field:

!





This is how I added it to the message section of the email trigger:

!





Are you able to see what I did wrong? What should it be?



Thx.
> @cyberwhite said:

> Are you able to see what I did wrong? What should it be?

Yes, the pipe should be ${e://Field/outputlinebreaks}
Hi @TomG and @Alex_WLU ,



I am trying to do the same thing with my email triggers. I want to replace the comma and just have the wording on the next line. As you can see in the samle email below, the formatting is not correct.

Each class should be formatted as this:

Date

Time

Name



I added the ${e://Field/outputlinebreaks} in and was unsuccessful.



!

Sorry to Highjack an old thread, TomG but I was wondering if this would be possible but instead of leveraging regular text entry responses, i would like to leverage the text fields you can add to a matrix table. is this possible?

image.png



Leave a Reply