Hi,
I'm new to Power Automate and created a flow to get Microsoft Forms responses submitted to create a SharePoint page (based on a pre-created page template) on a Modern Communication SharePoint Site; essentially following the step-by-step instruction from this tutorial: https://www.youtube.com/watch?v=QtBqeEEOgdE.
My Forms has a question "Session description" that is a long text answer field and the text of the submitted response will then placed into a modern text webpart of the SharePoint page via the "Save Page - https POST" step:
However, I find that whenever the submitter include a "linebreak/next line" in their Forms response, the "Save Page - https POST" step fails and the error message I get is "BadGateway" with the message:
"There was an error deserializing the object of type Microsoft.SharePoint.Publishing.SitePageFieldsData. Encountered invalid character '\n'.....". Upon looking at the raw input message of that step, I see that there are these "\n" characters that are automatically injected between the sentences, which upon testing is confirmed to be when the submitter line break their text when typing out their responses in Forms.
I've tried looking up forums but haven't come across any resources that seem to be identical to my problem. Any help to how to clear these '\n' characters would be much appreciated, since my flow has had more Failed runs than Successful runs so far due to this error. Thank you so much!
Solved! Go to Solution.
Try solution given in this thread...
https://powerusers.microsoft.com/t5/Building-Flows/Replace-Newline-in-Flow-Expression/td-p/57333
uriComponentToString(replace(uriComponent(body('Html_to_text')), '\n', ''))
Can you replace line break character like below?
replace(variables('Melcode'), '\n', '')
OR
replace(variables('Melcode'), '\n', '<br>')
Hi PrasedAthalye,
Thanks for the tip!
I've tried replace expression, but the '\n' seem to be displayed only in the "Show raw input/output" and therefore it doesn't seem to be selected and replaced.
As a test, I tried the following to see if maybe the way I wrote the expression is incorrect. - the following does work.
replace(outputs('Get_response_details')?['body/rd47ed83d812c4fbfabccdbba54g913gh'], 'lorem ipsum', 'LOREM IPSUM')
However when the latter part is changed to '\n' - it doesn't work.
replace(outputs('Get_response_details')?['body/rd47ed83d812c4fbfabccdbba54g913gh'], '\n', 'WHATEVER')
I have no idea how to replace the \n that's seen only in the raw data.....
OK. Can you use HTML to text action first to convert entire HTML to a text format and then use replace on it?
Unfortunately, still not working.
I thought HTML to text fixes it, until I saw that its' raw outputs added "\n" to where the text line break to the next line in the body 🙄, which when I do the Replace expression, it still not be detected as these new "\n" is also only seen in the raw outputs....
Try solution given in this thread...
https://powerusers.microsoft.com/t5/Building-Flows/Replace-Newline-in-Flow-Expression/td-p/57333
uriComponentToString(replace(uriComponent(body('Html_to_text')), '\n', ''))
Thank you so much for this, this does the trick!!
Although it seems like the "\n" character is seen as "%0A", so I just made the slight adjustment with your suggested expression. I tested without using "Html to text" too, and the following seems to work as expected. I could probably clean up the expression nicer with additional variables.
uriComponentToString(replace(uriComponent(outputs('Get_response_details')?['body/rd47ed83d812c4fbfabccdbba54g913gh']), '%0A', '<br>'))
With that, it then put the text onto the page with the intended <br> as the originally submitted response thru the Microsoft Forms:
Again, I really appreciate your help and troubleshooting with this!
The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.
Announcing a new way to share your feedback with the Power Automate Team.
Learn to digitize and optimize business processes and connect all your applications to share data in real time.
User | Count |
---|---|
64 | |
23 | |
16 | |
15 | |
11 |
User | Count |
---|---|
121 | |
36 | |
32 | |
28 | |
26 |