Removing HTML Tags and retaining same tags

Sam196
Kilo Expert

To begin with, all help is much appreciated. Thank you!

I have two description fields 1. HTML type 2. String Type

When a user adds content to the HTML description (u_description), I am using the following script to copy the content to the string type description (description) field. Then all the html tags (<p>, </p>, <strong>...) were showing, so I used the code on line 4 to remove the characters that can helped remove the html tags.

Now, the problem is when the data is copied to string field, it takes away some special characters and showing the code format. 

[     '&' - &amp;     |||     '<' - &lt;    |||    '>' - &gt;    ||||     '+' - &#43;      |||     '>' - &gt;    ]

I am not good at coding, so can someone please help me figure out how to convert the code of the character back to the actual character value. If possible all above. Ex: 'Sam &amp; Peter' convert to 'Sam & Peter'

 

(function executeRule(current, previous /*null when async*/) {

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

})(current, previous);
2 REPLIES 2

Sukhbir Singh2
Giga Guru

Hi 

Have you tried this function-

GlideSPScriptable().stripHTML(htmlText)

Please mark my answer correcr/helpful, if it helped.

Thanks

Ravi9
ServiceNow Employee
ServiceNow Employee

take a look at this