Converting HTML content of an field in a table to Plain Text of another table

mazin690
Tera Contributor

How to convert the HTML content of an field from my incident form to the custom table (New Table) field  which is Plain text?

Incident html field (u_Htext)  - Type -- HTML 

custom table field - (u_description) -- Type -- String

 

Any idea will be appreciatable

 

14 REPLIES 14

asifnoor
Kilo Patron

Hi Mazin,

When you say convert, do you want to strip the HTML tags before storing into the custom table field? If yes, then you can simply strip them like this.

 

var gr=new GlideRecord("incident");

gr.addQuery("sys_id",incident_sys_id);

gr.query();

if(gr.next()) {

var str=gr.u_Htext;


var strip_html = str.replace(/(<([^>]+)>)/ig,"");

current.u_description = strip_html;

current.update();

}

Mark the comment as correct if this solves.

Hi Asif,

 I want the whole content which is their in HTML format in incident table field.. it should accept the same in the plain text field... it is not just fetching the text from it... like formating has to be retained in plain text field..

So what issue are you facing when you try to store it directly

 

var str=gr.u_Htext;


current.u_description =str.toString();

i dont want to strip off the html tag .... i wnt the same format whtever is present in the html field.. same has to be captured in the plain text field.. because plain text field is not accepting the HTML content... not just the text ... i need the whole content in the plain text field.