How to display html field type data in UI Page without tags.

MithileshK
Tera Contributor

Hi,

I have a UI Page where I need some advice/help on how can we display the text from html field type.

Right now, when am trying to display the field value , it is coming as "html" with tags included.

 

field name : details

 

My code below:

HTML:

<div class="related-list">
<g:macro_invoke macro="sn_major_inc_mgmt_pir_report_related_list_table" table="cmdb_ci_outage" title="${gs.getMessage('Outages')}" query="JOINcmdb_ci_outage.sys_id=task_outage.outage!task=${jvar_sysparm_sys_id}" columns="cmdb_ci,type,message,begin,end,details"/>
</div>

 

UI Macro used here is a read-only OOTB one "pir_report_related_list_table".

 

output: 

Outages
Service Type Message Begin End Details
JiraOutageTeams were unable to track, plan, report07/11/2022 14:43:0307/11/2022 16:08:42<p><em>Update from Major Incident Management issued on </em>08/11/2022 18:13:53<em>.</em></p> <p><em>Description -</em>The Jira application was unavailable, or slow, when using URL https://jira.nbnco.net.au/. [https://jira.nbnco.net.au/.]</p> <p><em>Impact -</em>Teams were unable to track, plan, report and manage work or project tasks using the Jira application. Ongoing Jira application unavailability, or slowness, may have delayed the scheduled delivery of work and project tasks.</p> <p><em>Latest actions -</em>A successful monitoring period over the business day has occurred, with no slowness due to server resources after last night&#39;s rollback.</p>
 
TIA
5 REPLIES 5

jaheerhattiwale
Mega Sage

@MithileshK 

 

As details is HTML field it will give the html tags in it.

 

I would suggest to create a new field on outage table and move the details field value to new field without html tags.

Remove html tags like below

 

 

Script:

var str = "HTML STRING HERE"
str = str.replace( /(<([^>]+)>)/ig, '');
gs.info(str);
 
Then use the new field in the ui page.
 
Please mark as correct answer if this solves your issue.
Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

Thanks @jaheerhattiwale .

May i ask, if there is any other way than to create a new field. Just for this report, i would be creating this new field, which i don't think is recommended. Also, saw some snow recommendation too, who suggested this same solution, but wanted to know if there is a way to parse this html field in UI page and use that as output ?

@MithileshK Yes creating a new field only for this purpose is not good idea.

 

As you used ootb ui macro I suggested that.

 

But if you write a custom ui page then you can remove html tags in ui page itself.

 

Let me try to create custom ui page.

 

Btw where you want to show the output and how you are getting outage sys I'd?

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

Ankur Bawiskar
Tera Patron

@MithileshK 

so you are invoking that UI macro but from where?

How are you passing the field value to that?

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader