Keep line breaks when piping text from Text Entry / multiple line box | XM Community
Skip to main content

Hi, everyone -

My survey has a Text Entry question type (with multiple lines enabled). I’m piping this information into an email trigger / workflow; however, line breaks are being removed when the response is sent.

 

For example, if someone enters this into the Text Entry box:

One

Two

Tree

Four

 

It gets turned into a single line when the result is emailed, so “One Two Three Four.”

 

How do I preserve the line breaks when I’m piping that information? 

You can try this.  You can replace space with html <br> tag and then save it in another hidden text variable. And then use that variable in your email format. 


That sounds like it would work! Would that be done by applying javascript to the question or by altering the source HTML of the question itself? (My apologies - I am still getting the hang of Qualtrics!) Do you know of a tutorial by chance?


There is no such standard documentation. You can try below code.

First create two text entry variables.

Hide 2nd text entry using below code’s first line. make sure to replace #QID5 and #QR~QID5 with your second variable’s ID. And #QR~QID4 with your first variable’s ID. we use \\ double forward slash to handle special characters in jQuery. So if your QID is #QR~QID4, then write it as #QR\\~QID4.

Copy below code, apply changes as mentioned in above para and use it. it will work.

	jQuery("#QID5").css('display','none'); // Hide hiddenQ5


jQuery("#NextButton").click(function(){
var lines = jQuery("#QR\\~QID4").val().split("\n");
var inputText ="";
for(var i=0;i<lines.length;i++)
{
var inputText =inputText + linesti];
if(i<lines.length-1)
{
var inputText =inputText + "<br>";
}
}

jQuery("#QR\\~QID5").val(inputText); // Set value in hidden variable
});

 


Thanks, Arun! Here’s what I’ve done… just to confirm: Is this all correct?

I made a dummy survey to test this out and keep it simple. The first question is QID1 and the second hidden question is QID2. Here are some screenshots:

 

And then this is the email trigger I’ve set up:

 

I tested it out and entered this the first question’s text box:

One

Two

Three

Four

 

However, here’s how it came through in the final email:

One<br>Two<br>Three<br>Four


Can you please replace <br> with "&#13;", if it will not work then replace with "\n". Actually piping text is bringing the data on html text instead of source code plain text page. That's why it is happening. Please update your JS code, replace <br> with unicode and then check.


Do one thing. Keep your script as it is. Store your hidden variable data under Embedded field and pipe that embedded field under email template. Embedded field can convert BR. Try this. I'm sure this will work.


Hi @cassieh 

Input text entry doesnt take HTML, hence, you need to use embedded data for it. Update the codes replace this line

jQuery("#QR\\~QID5").val(inputText);

with this line:   

 Qualtrics.SurveyEngine.addEmbeddedData("inputText", inputText);

create “inputText” embedded Data in your survey flow and pipe that in your email.

Also, you don’t need hidden question so you can remove this line 

jQuery("#QID5").css('display','none');
 

Hope this helps!


Awesome! The embedded data method did the trick. Arun and Deepak, thank you so much for your help! This is going to be a life-saver for our entire team! 


Hi all,

Hoping to get some help here stumbling across this post. I’m looking to achieve the same thing as OP, sending text entry via email with line breaks.

I can’t figure out why my JavaScript code won’t work.

  • The Q5 in Block 2 has a QID=7.
  • My JS code is found in Q7 “Thanks for taking survey” and I have a slight change in that it is being loaded addOnLoad of the page.
  • I’m using Q8 to confirm the text is displaying correctly which is hasn’t been so far.

I’ve tried changing “<br>” to  "&#13;" and "\n" but nothing seems to be working. Would love some help if you can provide it

---

Qualtrics.SurveyEngine.addOnload(function()
{
var lines = jQuery("#QR\\~QID7").val().split("\n");
var inputText ="";
for(var i=0;i<lines.length;i++)
{
var inputText =inputText + linesTi];
if(i<lines.length-1)
{
var inputText =inputText + "<br>";
}
}
Qualtrics.SurveyEngine.addEmbeddedData("inputText", inputText);

});

 


@Demerson 

Your JS is trying to pull QID7 value from next screen next question which wouldn’t be possible, you can use Qualtrics piped text like ${q://QID7/ChoiceTextEntryValue} directly or I would recommend doing it on same page on next button click.

Hope it helps!


@Deepak 

Thanks for the response. Do you mean move the “Thanks for taking survey” question up to the same block like below? I’ve updated the code but I’m not sure if this is what you were referring to?

Appreciate the help

Qualtrics.SurveyEngine.addOnload(function()
{
var lines = jQuery("${q://QID7/ChoiceTextEntryValue}").val().split("\n");
var inputText ="";
for(var i=0;i<lines.length;i++)
{
var inputText =inputText + linesti];
if(i<lines.length-1)
{
var inputText =inputText + "<br>";
}
}
Qualtrics.SurveyEngine.addEmbeddedData("inputText", inputText);

});

 


@Demerson 

You can keep the thanks for taking survey question on next page and on the original text entry question (QID7) you can include the below JS code.

Qualtrics.SurveyEngine.addOnReady(function()
{

jQuery('#NextButton').click(function(){
var lines = jQuery("#QR\\~QID7").val().split("\n");
var inputText ="";
for(var i=0;i<lines.length;i++)
{
var inputText =inputText + linesni];
if(i<lines.length-1)
{
var inputText =inputText + "<br>";
}
}
Qualtrics.SurveyEngine.addEmbeddedData("inputText", inputText);

});
});

Hope it helps!


Yep it worked. Thanks so much @Deepak ! This is going to help our team so much!


Leave a Reply