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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Escape, replace Email....
Power Automate
Unanswered

Escape, replace Email.Body characters

(0) ShareShare
ReportReport
Posted on by 23

Hey , i am trying to build a flow that will extract dataa from emails and put into HubSpot. 

I get to the point where i need to put the whole email body(html) into hubspot. 
Been working for hours to find a way to replace the characters so it gets a propper json file. 

i'm trying to make a js to replace unwanted characters ex: new line with \n, etc . 
----------
var text=`%IndividualMail.Body%`;
        text = text.replace(/\\/g, '\\\\');
        text = text.replace(/\t/g, '\\t');
        text = text.replace(/\n/g, '\\n');
        text = text.replace(/'/g, "\\'");
        text = text.replace(/"/g, '\\"');
WScript.Echo(text);

------------

The issue is that at runtime, i get : 

C:\Users\cd\AppData\Local\Temp\Robin\r5qxrvkdmy1.tmp(1, 10) Microsoft JScript compilation error: Invalid character.

 

Of ocurse the body_email looks something like : 

<META HTTP-EQUIV="Content-Type" CONTENT="text/html;charset=Windows-1252">
 
<!DOCTYPE html>
 
<html>
 
<head>
............................
</style>

 

 

==============

 

 

But it shoud turn into something like:

"hs_email_html": "<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html;charset=Windows-1252\">\n\n<!DOCTYPE html>\n\n<html>\n\n<head>\n\t<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">\n\t\n</head>\n\n<body topmargin=\"0\">\n\n<title></title>\n<meta charset=\"utf-8\"><meta name=\"viewport\" content=\"width=device-width\">\n<style type=\"text/css\">#outlook a{padding:0;} .ReadMsgBody{width:100%;} .ExternalClass{width:100%;} .ExternalClass, .ExternalClass p, .ExternalClass span, .ExternalClass font, .ExternalClass td, .ExternalClass div {line-height: 100%;} body, table, td, a{-webkit-text-size-adjust:100%; -ms-text-size-adjust:100%;} table, td{ms
 
=========
Any ideeas ? Thank you 
  • Agnius Bartninkas Profile Picture
    Most Valuable Professional on at

    You can also simply use Replace text to replace the values. It accepts regular expressions, so you can pass \n to replace any newlines with a literal \n, if you activate regular expressions, but leave the escape sequences off for the text to replace the value with.

    You will need a separate Replace text action for each different value you want to replace the original values with.

    Alternatively, you could use the Escape text for regular expression action to escape most special characters, but it's limited to what it escapes (, *, +, ?, |, {, [, (,), ^, $,., #, and whitespace).

    -------------------------------------------------------------------------
    If I have answered your question, please mark it as the preferred solution. If you like my response, please give it a Thumbs Up.

    I also provide paid consultancy and development services using Power Automate. If you're interested, DM me and we can discuss it.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Automate

#1
Mohsin Ali Profile Picture

Mohsin Ali 426

#2
11manish Profile Picture

11manish 345 Super User 2026 Season 2

#3
M Bilal Khan Profile Picture

M Bilal Khan 308

Last 30 days Overall leaderboard