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

Manish Vinayak1
Tera Guru

Did you try placing your HTML content inside no_escape tag?

 

no_escape

  • Description: The system, by default, uses escaped output as a security measure. Output placed inside of no_escape tags is not escaped before output. Be careful when using these tags, because if user input is displayed here it can open a security vulnerability on the page.
  • Parameters: None.
  • Example:
    <g:no_escape>
     ${jvar_raw_html_data}
    </g:no_escape>

 

Here is an example:

find_real_file.png

Result:

find_real_file.png

 

If I add the no_escape tag:

find_real_file.png

Result:

find_real_file.png

 

Give it a try and see how it goes. Hope this helps!

Cheers,

Manish

 

It didn't seem to work for me.

 

<b>Reason: &#160;</b><g:no_escape>${jvar_body}</g:no_escape>

 

Shows:

 

Reason:  <p>Here is the body.</p>

 

Here is my UI Page code

 

<?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:ui_form>
  <!-- Get the values from dialog preferences -->
  <g:evaluate var="jvar_type" expression="RP.getWindowProperties().get('type')" />
	<g:evaluate var="jvar_ci" expression="RP.getWindowProperties().get('ci')" />
	<g:evaluate var="jvar_start" expression="RP.getWindowProperties().get('start')" />
	<g:evaluate var="jvar_end" expression="RP.getWindowProperties().get('end')" />
	<g:evaluate var="jvar_time_range" expression="RP.getWindowProperties().get('time_range')" />
	<g:evaluate var="jvar_desc" expression="RP.getWindowProperties().get('desc')" />
	<g:evaluate var="jvar_loc" expression="RP.getWindowProperties().get('loc')" />
	<g:evaluate var="jvar_body" expression="RP.getWindowProperties().get('body')" />
   <!-- Set up form fields and labels -->
	<i>Subject: </i>
	<p></p>
	${jvar_type} Notification - ${jvar_desc} - ${jvar_start} ${jvar_time_range};	
	<p></p>
	<i>Email body: </i>
<p></p>
<center><u><b>${jvar_type} Notification</b></u></center>
	<p></p>
	<b>Date: &#160;</b>${jvar_start}
	<p></p>
<p></p>
	<b>Time: &#160;</b>${jvar_time_range}
	<p></p>
	<p></p>
	<b>Location(s) affected: &#160;</b>${jvar_loc}
	<p></p>
	<p></p>
	<b>System(s) affected: &#160;</b>${jvar_desc}
	<p></p>
	<p></p>
	<b>Reason: &#160;</b><g:no_escape>${jvar_body}</g:no_escape>
	<p></p>
	<center><p>If you have questions about the implications of this event on your role, please contact your supervisor.</p>
		<p></p>
		<p>"Contact IT Support at XXX to report any other technical issues.</p></center>
	<p></p>
</g:ui_form>
</j:jelly>

 

After some further messing around, I think I'm a step closer after following your lead BUT there are a few issues.

First issue is that I can't use that evaluate until after the record is saved.  That is less than optimal as the whole reason for running this client-side is to show current changes,

 

Second issue in detail below.

Source field:

Here is the body.

 

This snippet:

<b>Reason alt: &#160;</b><g:no_escape>${rec.u_body}</g:no_escape>

 

Produces:

Reason alt:  

Here is thebody.

 

Note the space that for whatever reason just disappears.  

 

Hi Shane,

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.

On your second issue:

Normally Jelly trims the whitespaces from the rendered result. You could use j2:whitespace tag to allow whitespaces to be rendered. Here's the documentation on using j2:whitespace

https://docs.servicenow.com/bundle/newyork-application-development/page/script/general-scripting/con...

Whitespace

Normally, white space is removed by Jelly. To keep it, you must specify that it not be trimmed.

For example, the following keeps the space after the colon.

<j2:whitespace trim="false">${gs.getMessage('Did you mean')}: </j2:whitespace>


Try the following snippet:
<j2:whitespace><b>Reason alt: </b><g:no_escape>${rec.u_body}</g:no_escape></j2:whitespace>

Hope this helps!

Cheers,

Manish