Can I properly show a value from an HTML field in a UI Page?

Shane J
Tera Guru

Is there any way to show the value of an HTML field properly when it's delivered in a pop-up that shows a UI page?

Right now any HTML comes across as regular text and isn't translated in the XML of the UI Page.

See here for reference: https://docs.servicenow.com/bundle/geneva-servicenow-platform/page/script/client_scripts/reference/r...

 

1 ACCEPTED SOLUTION

Hi Shane,

 

Here's an example of how you can get the values using client script in a UI Page Preview and set the values in the page content.

find_real_file.png

In the above script, in the Client script section, you'll see that GlideForm,i.e., g_form methods are used to access the value of "short_description". I have included comments to give you an idea of the purpose of those statements.

The values accessed using g_form methods are then set in the UI Page content using DOM Methods (it is not going to get impacted by any upgrade as it is your own HTML code, which is not going to change its document structure). 

So, here is the incident form where I tried previewing the UI Page:

find_real_file.png

 

And here is the preview result using the UI Page:

find_real_file.png

 

This implementation got the results from the client side of the form, not the server side. So you'll get the current values even if they're not yet saved.

 

Hope this helps!

Cheers,

Manish

View solution in original post

12 REPLIES 12

There is also $[SP]

<b>Reason alt:</b>$[SP]<g:no_escape>${rec.u_body}</g:no_escape>

Manish you should write up a blog on how to create a Preview UI Action.  😉

Haha, if there are no similar blogs / articles, then yeah maybe 😉

Can you explain this more:

 

Regarding your first issue:

If you want to get details from client side you can trigger glideform methods on the client script part of the UI Page or maybe within a script tag in the UI Page, which is set to execute on load. You can define "ID" on each HTML element where you want to update the content, then can use javascript functions to set those values. This will happen after the UI Page has rendered, i.e. <g:evaluate> has already been processed. So you can choose to update those values only if there is a change in the values which were fetched from Server side.

 

I can't find any examples of how to call a variable from the Client Script - everything refers to using 'input' fields, which I have no interest in for this.

Hi Shane,

 

Here's an example of how you can get the values using client script in a UI Page Preview and set the values in the page content.

find_real_file.png

In the above script, in the Client script section, you'll see that GlideForm,i.e., g_form methods are used to access the value of "short_description". I have included comments to give you an idea of the purpose of those statements.

The values accessed using g_form methods are then set in the UI Page content using DOM Methods (it is not going to get impacted by any upgrade as it is your own HTML code, which is not going to change its document structure). 

So, here is the incident form where I tried previewing the UI Page:

find_real_file.png

 

And here is the preview result using the UI Page:

find_real_file.png

 

This implementation got the results from the client side of the form, not the server side. So you'll get the current values even if they're not yet saved.

 

Hope this helps!

Cheers,

Manish