The CreatorCon Call for Content is officially open! Get started here.

how to pass variable from client script to HTML is ServiceNow UI page

nikhil_001
Tera Contributor

Hi All,

 

can anyone guide me how can we pass variable from client side to HTML in UI Pages?

 

Thanks

1 ACCEPTED SOLUTION

So, if the reason for why you want to get the contents of the <p/> element is to remove the HTML tags, that is not how it should be done.

You just need to enclose the phase 1 interpolation (${...}) within a <g:no_escape/> tag:

<p><g:no_escape>${ content }</g:no_escape></p>

 

View solution in original post

7 REPLIES 7

-O-
Kilo Patron

What kind of variable?

nikhil_001
Tera Contributor

Hi,

I have created a UI page and our requirement is to get the field value(HTML type field) in the UI Page,but when we are simply gliding the table and getting the HTML field value ,its coming with the tags(<p> <strong>this is an example</strong></p>) but we want the values without the tags

I tried using regex:

var gr=new GlideRecord("abc");
gr.addQuery('sys_id', '${sysparm_sys_id}');
gr.query();
while(gr.next()){

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

}

now here problem is how can pass this content from Client side to HTML in UI page

nikhil_001_0-1679384599425.pngnikhil_001_1-1679384639139.png

 

So, if the reason for why you want to get the contents of the <p/> element is to remove the HTML tags, that is not how it should be done.

You just need to enclose the phase 1 interpolation (${...}) within a <g:no_escape/> tag:

<p><g:no_escape>${ content }</g:no_escape></p>

 

nikhil_001
Tera Contributor

This was really helpful.

 

Thank you