Scripting Help- invalid HTML

Su522
Kilo Sage

Can anyone help me write a script to resolve this error:

Email validation failed: Email body is comprised of invalid HTML.

 

It is generated in Flow Designer when there are invalid tags in an HTML email reply.

I'm using the 'Send Email' action to send staff a notification when an email reply is received on a ticket. 

I think this needs a Regex script?

 

Help is greatly appreciated!

1 ACCEPTED SOLUTION

Su522
Kilo Sage

Clean HTML- Flow Designer Action

Create a FD Action with Input:

Su522_0-1726248276076.png

 

Script Step:

Su522_1-1726248276078.png

 

Script:

(function execute(inputs, outputs) {  

 

// Input variable

  var htmlString = inputs.htmlString;

 

// Remove HTML tags using regular expressions

var cleanString = htmlString.replace(/<br ?\/?>|<\/p>/ig, "\n");

cleanString = cleanString.replace(/<script[^>]+>.*<\/script>/ig);

cleanString = cleanString.replace(/<style[^>]+>.*<\/style>/ig);

cleanString = cleanString.replace(/<[^>]+>/g, "");

 

// Output variable

outputs.text_out = cleanString;

 

})(inputs, outputs);

 

Su522_2-1726248276079.png

 

Create Action Output:

Su522_3-1726248276081.png

 

Su522_4-1726248276081.png

 

Call the FD Action from the FD Flow:

(this will get the latest email response)

Su522_5-1726248276083.png

View solution in original post

4 REPLIES 4

Mayur2109
Kilo Sage
Kilo Sage

Hi @Su522 ,

 

Refer below post.

https://www.servicenow.com/community/developer-forum/flow-design-giving-email-validation-failed-emai... 

 

Please check and Mark Helpful and Correct if it really helps you.

Regards,
Mayur Shardul

ServiceNow Rising Star 2024

Hi,

Unfortunately, I've read that article and it is not helpful. Can you elaborate on how to fix this? With scripting.

How can we actually fix this, details needed please

Thank you

Su522
Kilo Sage

Clean HTML- Flow Designer Action

Create a FD Action with Input:

Su522_0-1726248276076.png

 

Script Step:

Su522_1-1726248276078.png

 

Script:

(function execute(inputs, outputs) {  

 

// Input variable

  var htmlString = inputs.htmlString;

 

// Remove HTML tags using regular expressions

var cleanString = htmlString.replace(/<br ?\/?>|<\/p>/ig, "\n");

cleanString = cleanString.replace(/<script[^>]+>.*<\/script>/ig);

cleanString = cleanString.replace(/<style[^>]+>.*<\/style>/ig);

cleanString = cleanString.replace(/<[^>]+>/g, "");

 

// Output variable

outputs.text_out = cleanString;

 

})(inputs, outputs);

 

Su522_2-1726248276079.png

 

Create Action Output:

Su522_3-1726248276081.png

 

Su522_4-1726248276081.png

 

Call the FD Action from the FD Flow:

(this will get the latest email response)

Su522_5-1726248276083.png

NayanM
Tera Contributor

Hi @Su522  ,

I am facing the same issue in my flow designer. Hence, the flow is failing. Just need to know where have you put the new created action in the flow ? Have you used it instead of Send Email ? Can you just brief a little more on the steps.

NayanM_0-1736159241232.png