HOw to convert HTML to plain text in a UI Action
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2018 04:02 PM
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't use XXX because it makes things worse!"
Any ideas how to remove the HTML special character formatting in a UI Action?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2020 07:04 AM
Thank you for posting this it works for me too.