
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 :
==============
But it shoud turn into something like:
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.