HOw to convert HTML to plain text in a UI Action

gjz1
Giga Expert

I have a requirement to update the contents of a field from one table to the field of another table if a specific action occurs.  The sending table's field is HTML, the receiving table's field is string.

I need to convert the HTML field to plain text so it renders correctly in the receiving table.  I've searched the community and find a lot of information (that works) to convert the tags but nothing to convert the special characters.

My UI Action:

var rhtml = current.html_field.getDisplayValue();
var txtDesc = rhtml.replace(/<\/?[^>]+(>|$)/g, "");

var gr = new GlideRecord("my_table");
gr.get(current.my_table);
gr.setValue("string_field", txtDesc);
my_table.update();

I entered "So, don't use XXX because it makes things worse!" in the HTML field, after running the above UI Action the data in the text field is "So, don&#39;t use XXX because it makes things worse!"

Any ideas how to remove the HTML special character formatting in a UI Action?

 

5 REPLIES 5

Thank you for posting this it works for me too.