Remove HTML tags

Tom Lapkowicz
Tera Expert

Hello.  I would like to set it that any time project_status.executive_summary (an HTML field) is updated then project_status.u_exec_summary (a text field) is updated to the value of project_status.executive_summary without the HTML tags.  Any idea how to do this?  I tried a Business Rule and a workflow but no luck.  Thank you.

1 ACCEPTED SOLUTION

Tom Lapkowicz
Tera Expert

Thanks Shivalika.  I ran this and it removed most of the tags but this still shows:  won't this work

(the apostrophe in "won't" appears to show as ')

View solution in original post

6 REPLIES 6

Shivalika
Mega Sage

Hello @Tom Lapkowicz 

 

Please use below 👇 script in your business rule which you created - 

 

var plainText = current.executive_summary.toString()
.replace(/<br\s*\/?>/gi, '\n') // Convert <br> to line break
.replace(/<[^>]*>/g, ''); // Remove remaining tags
current.u_exec_summary = plainText;

 

I tested it with this """<p><strong>Project is on track.</strong> All milestones met.<br>Next review in <em>two weeks</em>.</p>

""" 

 

And it returns me - """Project is on track. All milestones met.

Next review in two weeks

.""""

 

So it works. 

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket. 

 

Regards,

 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY

Tom Lapkowicz
Tera Expert

Thanks Shivalika.  I ran this and it removed most of the tags but this still shows:  won&#39;t this work

(the apostrophe in "won't" appears to show as &#39;)

Hello @Tom Lapkowicz 

 

I am glad this worked for you. Kindly mark my answer as helpful and accept solution 🙂. This will motivate me a lot to continue sharing. 

 

Let me check this apostrophe in my system and grt back. I didn't test with apostrophe one. 

 

Regards,

 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY

Hello @Tom Lapkowicz 

 

Please use below 👇 updated script - 

 

(function executeRule(current, previous /*null when async*/) {

 

    // Get the raw HTML

    var html = current.executive_summary.toString();

 

    // Decode HTML entities using GlideStringUtil

    var decoded = GlideStringUtil.unescapeHTML(html);

 

    // Convert <br> to newline (optional), then strip all other tags

    var plainText = decoded.replace(/<br\s*\/?>/gi, '\n')

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

 

    // Set the plain text

    current.u_exec_summary = plainText;

 

})();

 

Kindly mark both my answers as helpful and accept solution as both are correct. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket. 

 

Regards,

 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY