Remove HTML Tags

Amit Pandey
Kilo Sage

Hello Everyone,

We have ebonding in place using Scripted Rest API. The description field in the client's snow is of HTML type and mine is of string type field. This is why I am getting HTML tags in description field. How can I remove these tags? 

Regards,

Amit

1 ACCEPTED SOLUTION

Mahesh Kumar3
Giga Guru
Giga Guru

Hi Amit,

 

Just use this function to pass your html body and it will return you content in text:

 

function getFinalText(text) {
    // Replace all <br /> tags with a CRLF
    var regX1 = /<br\s\/>/ig;
    var text2 = text.replace(regX1, String.fromCharCode(13));
    // Replace all remainging HTML tags with ""
    var regX2 = /(<([^>]+)>)/ig;
    var finalText = text2.replace(regX2, "");
    return finalText;
}

 

Regards,

Mahesh Kumar

View solution in original post

10 REPLIES 10

Mahesh Kumar3
Giga Guru
Giga Guru

Hi Amit,

 

Just use this function to pass your html body and it will return you content in text:

 

function getFinalText(text) {
    // Replace all <br /> tags with a CRLF
    var regX1 = /<br\s\/>/ig;
    var text2 = text.replace(regX1, String.fromCharCode(13));
    // Replace all remainging HTML tags with ""
    var regX2 = /(<([^>]+)>)/ig;
    var finalText = text2.replace(regX2, "");
    return finalText;
}

 

Regards,

Mahesh Kumar

Hi Mahesh,

I have 2 tags in my HTML field, <p> and <a>. I want to keep the <a> tag so that it maintains the hyperlink functionality. Can you please suggest how to remove the <p> tag and keep the <a> tag.

AnirudhKumar
Mega Sage
Mega Sage

Use below script to parse out the html tags:

var res = str.replace(/<[^>]*>/g, '');

 

str is your html field value with the HTML tags

Jonathan102
Tera Guru

Mahesh,

I am having this same issue with a UI action on the Project table that creates a Change Request when used.  The Business Case field on Project is an HTML field type and this verbiage is getting added to the Justification field on the Change Request.  All of the tags/HTML code has started showing up in the Justification field.  The UI Action script is very simple, any suggestions on how to resolve this issue?  

 

Script: 

function createChange() {
var cr = new GlideRecord("change_request");
cr.short_description = current.short_description;
cr.description = current.description;
cr.justification = current.business_case;
cr.parent = current.sys_id;


var sysID = cr.insert();

var mySysID = current.update();

 

gs.addInfoMessage(gs.getMessage("Change Request {0} created", cr.number));
action.setRedirectURL(cr);
action.setReturnURL(current);
}