How to remove HTML Tags

KARAN24
Tera Contributor

Hi Team,

 

I need to copy the html field to another table with string field. It copies but with HTML tags and I have around 20k records . Please help how can I remove the HTML tags. Thanks. 

 

Thanks,

Karan

4 REPLIES 4

RaghavSh
Kilo Patron

If you are copying it through script use:

 

current.getDisplayValue('html_field_name');

OR 

gr.getDisplayValue('html_field_name'); // incase you are gliding that table.


Raghav
MVP 2023

AnubhavRitolia
Mega Sage
Mega Sage

Hi @KARAN24 

 

Please refer below code for reference:

 

var myHTML= "<div><h1>Jimbo.</h1>\n<p>That's what she said</p></div>";
var strippedHtml = myHTML.replace(/<[^>]+>/g, '');
gs.info(strippedHtml);

 

Same way you can use below function to remove HTML tags and make it string.

 

replace(/<[^>]+>/g, ' ');

 

 

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023

Saurav11
Kilo Patron
Kilo Patron

Hello,

 

Please use the below:-

 

var regex =  /( |<([^>]+)>)/ig;
var content =current.getValue("fieldname").replace(regex, " ");  

 

Please mark my answer as correct based on Impact.

Hello all

 

I am having same issue with a ui page. I have that annoying <p> showing up with my text, how do I remove/hide the <p>.

JuneAnderson_2-1713386131580.png

 

See HTML Below please 

 

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
    <g:evaluate jelly="true" object="true">
        var field_value;
        var demandId = "";
       
            var referrer = GlideTransaction.get().getRequest().getHeader('Referer');
        if(!gs.nil(referrer)) {
            var url = new GlideURL(referrer);  
            if(url) {
                demandId = url.get('sysparm_element');
            }
        }
       
        var gr = new GlideRecord('dmn_demand');
        gr.get('sys_id', demandId);
        field_value = gr.business_case.getDisplayValue();
                field_value;
    </g:evaluate>
    <style>
        .demand_name {
            text-transform: capitalize;
            display: inline-block;
            font-size: 18px;
        }
        .wide {
            height: 100%
        }

    </style>
    <table class="wide">
        <tr>
            <td style="text-align:center">
                <span class="demand_name"><b>${field_value}</b></span>
            </td>
        </tr>
    </table>
</j:jelly>