Remove HTML coding from incoming Incidents

Brian S5
Kilo Sage

Hi All,

 

I was wondering if someone could help me understand how to code this change.

Id like to remove all the html coding from this paragraph but not sure how to format the business rule. 

 

Below is an example of the text that appears in our description field (This field is not HTML)

 

[code]<h3>RESOLVED Problem  <i>test</i></h3><br><small>Problem detected at: 19:02 (UTC) 13.12.2022 - 19:47 (UTC) 13.12.2022 (was open for 45 min)</small><hr><b>1 impacted service</b><hr><br><div><span>Web request service</span><br><b><span style="color:#7dc540; font-size:120%">Requests</span></b><br><p style="margin-left:1em"><b><span style="font-size:110%">Failure rate increase</span></b><br>requests/min impacted<br>your fixed threshold of 50 % was exceeded to 100 %<br>Service method: </p></div><hr><p><a target="_blank" href="link">Open in Browser</a></p>[/code]was[code]<h3>OPEN  environment <i>Instance</i></h3><br><small>Problem detected at: 19:02 (UTC) 13.12.2022</small><hr><b>1 impacted service</b><hr><br><div><span>Web request service</span><br><b><span style="color:#dc172a; font-size:120%">Requests</span></b><br><p style="margin-left:1em"><b><span style="font-size:110%">increase</span></b><br>10.2 requests/min impacted<br>your fixed threshold of 50 % was exceeded to 100 %<br>Service method: All dynamic requests</p></div><hr><p><a target="_blank" href="link">Open in Browser</a></p>[/code]

 

This is in my current business rule that i pulled from the community, that does remove some of the HTML but not all of it such as [/code],<hr>,<br>

var desc=current.description;
desc= desc.replace(/<\/?[^>]+(>|$)/g,"");

 

 

Can someone recommend how to replace these HTML tags on Insert ? Thank you! 

5 REPLIES 5

SanjivMeher
Kilo Patron
Kilo Patron

Do you receive it as part of an email?

If yes, you can use body_text instead of body_html in the inbound action.


Please mark this response as correct or helpful if it assisted you with your question.

its not from an incoming email. Its from an integration with Dynatrace. They don't have a recommendation to remove the html properly. It creates a problem, and then uses an transform map to move it to an Incident. 

 

 

Can you try the below function and see if it works?

 

reference https://www.servicenow.com/community/developer-forum/how-to-convert-html-to-plain-text-in-a-ui-actio...

 

function decodeHTML(str) {
    var a = str.replace(/<\/?[^>]+(>|$)/g, ""); //Remove tags
    var b = a.replace(/&amp;/g, '&'); //Retain any ampersands that are just ampersands
    return b.replace(/&#(\d+);/g, function(match, dec) {
        return String.fromCharCode(dec); //Returns the special character from the decimal code representation and returns the entire decoded string.
    });
}

 


Please mark this response as correct or helpful if it assisted you with your question.

I created the function, but unsure how to call it in a business rule and output the text to the description field. This is the part I need help with.

 

I have this in my business rule, but I am stuck here.

var rem = new decodeHTML();
rem.decodeHTML(param1, param2);