web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Can not convert \n to ...
Power Automate
Answered

Can not convert \n to to preserve carriage returns in form data using Compose

(0) ShareShare
ReportReport
Posted on by 6
I will try to be as clear as possible, so please forgive the long explanation of what I am experiencing.

I have a form where users input information. Three of the questions have a multi-line text field for them to enter data, for example repro steps where they would enter a list of items such as:
1. Open URL xyz.com
2. Enter text "ABC" in field 1
3. Enter text "XYZ" in field 2

Notice that each of those is on a separate line.

When I am testing, I submit three lines with "test"
When I examine the form data in my Get Response Details step, I see this...
"r8fe775j37fy592bbbcbe7fb9a0c0e8ad""test\ntest\ntest",

I initialize a variable named varFormData where I have elements like this...
What is the issue Priority?
@{variables('varTicketPriority')}

Who is affected by this issue?
@{variables('varAffected')}

Detailed problem description:
@{body('Get_response_details')?['r8fe775j37fy592bbbcbe7fb9a0c0e8ad']}
 
I then create an email and add the body like this...
Form Data:
@{variables('varFormData')}

When the email is sent, the body of text related to the question with the multiline input is:
Detailed problem description:
test test test


I have tried several approaches to getting the lines of text to show on separate lines in the email, but I am unsuccessful. I have tried the following...

I created a variable named varComposedFormData as a string with no default value

I created a Compose action with the following function in it...
replace(variables('varFormData'), '\n', '<br>')
The raw input includes: Detailed problem description:<br>\ntest\ntest\ntest
The raw output includes: Detailed problem description:<br>\ntest\ntest\ntest


I then use a set variableaction, setting the variable varComposedFormData to the output of the Compose action. 
The raw input includes: Detailed problem description:<br>\ntest\ntest\ntest
The raw output includes: Detailed problem description:<br>\ntest\ntest\ntest

As you can see, the \n are not getting changed to <br> at all.

I have also tried the following in the Compose function

replace(variables('varFormData'), newline(), '<br>')
replace(body('Get_response_details')?['r8fe775j37fy592bbbcbe7fb9a0c0e8ad'],decodeUriComponent('%0D'),'<br>')

Nothing works for me so far. Does anyone know how I can convert the \n to <br> so that my emails will be formatted preserving the multiline input
 



 
Categories:
I have the same question (0)
  • Verified answer
    Pstork1 Profile Picture
    68,717 Most Valuable Professional on at
    Instead of replacing '\n' try replacing decodeUriComponent('%0A') instead.  %0D is a carriage return which is '/r'.  
     
    replace(variables('varFormData'), decodeUriComponent('%0A'), '<br>')

    ----------------------------------------------------------------------------------
    If this Post helped you, please click "Does this answer your question" and give it a like to help others in the community find the answer too!

    Paul Papanek Stork, MVP
    Blog: https://www.dontpapanic.com/blog
     
  • JB-14051605-0 Profile Picture
    6 on at
    Thank you for the reply.
     
    I got it figured out...

    Depending on where you copy solutions from, %0A could be misinterpreted as %OA because not all 0 contain the slash in them and different fonts can cause 0 to look like O. This is what my problem was. I had tried %OA, not %0A.

    Also, reading your solution caused me to dig a little deeper into my misunderstanding of CR and LF and their many code counterparts. decodeUriComponent('%0A') works perfectly. In fact, each question and corresponding form entry had a <br> added to it when I was setting the value of varFormData. When I was running one of my tests, I noticed that the existing new lines were getting replaced also. I deleted the <br> tags I had added, and now everything is working perfectly and I don't even need all the extra <br> tags I had added.

    Thank you!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 519 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 296 Moderator

#3
abm abm Profile Picture

abm abm 232 Most Valuable Professional

Last 30 days Overall leaderboard