Keep string field formatting in UI Page

Brad Tilton
ServiceNow Employee
ServiceNow Employee

I've got a UI Page that I am trying display some fields from one of my tables on. I have some multiline string fields that I am displaying on the UI Page, but when I display them, they lose all the formatting, specifically returns.

For example, if my string field on the form looks like this:

Here is some text
Here is more text

Then on the UI Page it looks like this:

Here is some text Here is more text

Is there any way to keep the formatting when displaying the data in the UI Page? It works just fine if I include those fields in email notifications.

5 REPLIES 5

john_roberts
Mega Guru

UI Pages are rendered as html which doesn't understand whitespaces and line feeds. You can add the 'br' tag to add the line feed.


Anurag Tripathi
Mega Patron
Mega Patron

Hi Brad,



I had a similar encounter where i needed line breaks on a ui page. This is how i did it



<j2:forEach var="jvar_upd" items="$[jvar_updates]">


  <br/>$[jvar_upd]


  </j2:forEach>




<br/> provided me the line break


-Anurag

Janel2
Mega Expert

<li> tags are an option too.   I used a UI page to list group memberships by doing the below.   You can probably just replace the lists with <br /> like John suggested.



<div name="blocky" id="block">


The user is already a member of the following groups:


<j:forEach var="jvar_groups" items="${group}">


  <p>${jvar_groups}</p>


</j:forEach>



<ul>


<j:while test="${gr.next()}">


  <li>${gr.group.name}</li>


</j:while>


</ul>


</div>


sammyb
Tera Contributor

Hi Brad, did you ever get to the bottom of this?



I've used <Pre> tags around multi-line fields pulled back from a glide query in a UI page to preserve formatting but this is a double edge sword as you lose font etc and have to restate it within the Pre tag. Whilst it does maintain CR, line breaks white space etc. it also maintains rank stupidity i.e. the 3000 character stream of consciousness in a description field with no formatting at all is returned as a single line in your UI Page!



I've been playing around with wrap commands within the Pre tag but not much luck yet, if your sure of your data then <Pre></Pre> might be of some help to you, you would certainly get



Here is some text


Here is more text



returned albeit it in Courier!