cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
schao
Regular Visitor

Submitted Forms responses to populate Modern SharePoint Pages

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.

full-flow.png

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: 

 

automate-sharepoint-https-post.png

 

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:

automate-raw-output.png

"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.

automate-body.png

 

automate-forms-response-linebreak.png

 

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!

1 ACCEPTED SOLUTION

Accepted Solutions

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', ''))
Please Like and Mark this as Answer if it resolves your Issue.

Power Automate Community

View solution in original post

6 REPLIES 6
PrasadAthalye
Community Champion
Community Champion

Can you replace line break character like below?

 

replace(variables('Melcode'), '\n', '')
OR
replace(variables('Melcode'), '\n', '<br>')
Please Like and Mark this as Answer if it resolves your Issue.

Power Automate Community
schao
Regular Visitor

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.

 

Screen Shot 2021-04-22 at 3.34.24 PM.png

 

 

 

 

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?

Please Like and Mark this as Answer if it resolves your Issue.

Power Automate Community
schao
Regular Visitor

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.... 

 

Screen Shot 2021-04-23 at 11.45.34 AM.png

 

Screen Shot 2021-04-23 at 11.49.13 AM.png

 

 

 

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', ''))
Please Like and Mark this as Answer if it resolves your Issue.

Power Automate Community
schao
Regular Visitor

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:

Screen Shot 2021-04-26 at 11.36.13 AM.png

Again, I really appreciate your help and troubleshooting with this! 

Helpful resources

Announcements
Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Users online (3,841)