Remove html tags when copying into a string field

jxa7987
Tera Expert

Hi,

I need to copy the html field to another table with string field. It copies but with HTML tags. Please help how can I remove the HTML tags. Thanks. 

find_real_file.png

7 REPLIES 7

Jaspal Singh
Mega Patron
Mega Patron

Hi,

 

You need to use regex. Something as below.

var desc=current.yourhtmlfieldname; //current if used in business rule
desc= desc.replace(/<\/?[^>]+(>|$)/g, "");

 

Try below in background script once.

var desc='<p>test1</p>';
gs.print('Original '+desc);

desc= desc.replace(/<\/?[^>]+(>|$)/g, "");
gs.print('html sanitized:'+desc);

Output:

find_real_file.png

mak1A4
Tera Guru

It's also possible to use an undocumented function of GlideSPScriptable

GlideSPScriptable().stripHTML(yourHtmlStr)

Hello @Martin,

How we can use this in Business rule? Can you please help with it?

Thanks,

Matang