How to remove HTML tags

pjsnow
Kilo Expert

hello All,

 

I have a trouble removing html tags, Please read the below details and suggest the best solution.

 

I have a table when i select a particular template it is displaying the whole message with the html tags, I don't want the tags to be appeared on the message content. where the good part is when I press send mail the HTML tags are removed and the original message is displayed on the outlook.
Major requirement is i don't want to c the message with HTML tags on the message box when a template is selected. Please suggest a best solution, Thanks in advance.

 

 

 

1 ACCEPTED SOLUTION

pratik_kumar
Giga Expert

Hi Prajwal ,



You can create a new field on you table and copy the HTML text to that filed using the below script.


You have to run this as a background script.



var so=new GlideRecord('-----------------'); //your table name


so.addNotNullQuery('-------------------'); //HTML field name or add a query condition as per your requirement.


so.query();


while(so.next())


{


var a= so.unit_description.getXHTMLValue();


a= a.replace(/&(lt|gt);/g, function (strMatch, p1){


return (p1 == "lt")? "<" : ">";


});


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


so.setDisplayValue('----------------------',b); // New field name


so.update();


}




- Please like or mark as correct/helpful as you see fit.


View solution in original post

9 REPLIES 9

Check if the below thread is helpful



JavaScript: How to strip HTML tags from string? - Stack Overflow



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

DM me on SLack @nate


pratik_kumar
Giga Expert

Hi Prajwal ,



You can create a new field on you table and copy the HTML text to that filed using the below script.


You have to run this as a background script.



var so=new GlideRecord('-----------------'); //your table name


so.addNotNullQuery('-------------------'); //HTML field name or add a query condition as per your requirement.


so.query();


while(so.next())


{


var a= so.unit_description.getXHTMLValue();


a= a.replace(/&(lt|gt);/g, function (strMatch, p1){


return (p1 == "lt")? "<" : ">";


});


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


so.setDisplayValue('----------------------',b); // New field name


so.update();


}




- Please like or mark as correct/helpful as you see fit.


Amol J
Kilo Contributor

<p ng-bind-html="myText"></p

 

It worked for me.

Vivek Verma
Mega Sage
Mega Sage

Hi,

 

//Strip HTML Tags from Comments and work notes
//Pass commnet in StripCommnet parameter.
stripHTMLTAG: function(stripComment){
stripComment = stripComment.replace(/<\/?[^>]+(>|$)/g, "");
stripComment = stripComment.replace('[code]', ' ');
stripComment = stripComment.replace('[/code]', '');
return stripComment;
},