How can I show line-breaks from string field in UI Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-14-2021 04:29 AM
Good morning everyone,
I have created a string field on the company table which looks like this, with this text in it:
I then have a client script which passes the value of that same field to a UI Page (using setPreference()):
function invokeMessage(){
//console.log('crisOut');
var company = g_form.getReference('company', alertNote);
function alertNote(company){
var an = company.u_active_notification;
if(!an){
//console.log('crisNo ');
return;
}
//console.log('crisYes ');
var gdw = new GlideModal('active_notification');
gdw.setTitle('Active Notification');
gdw.setPreference('sysparm_activeNotification', an); //pass the active note to the ui page
gdw.render();
}
}
I then grab the value in the UI Page like this:
<j:set var="jvar_active_note" value="${sysparm_activeNotification}"/>
<p class="modal-title h4 modal-header">${jvar_active_note}</p>
The end result is it displays the message fine, but note the line-breaks are not present in the UI Page:
What would be the best way to show the line-breaks, which are present on the string field on the form, in the UI Page too?
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-15-2021 01:47 AM
Hi Cris,
If your string is picking up on the newline characters in the top text box, you could try a string.replace(/\n/g, '<br></br>') to replace the javascript new lines with with HTML line breaks when it moves it to the lower text box.
Please mark my answer as Correct & Helpful, if applicable.
Thanks
Sandeep
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-15-2021 03:52 AM
Hi Sandeep,
I have replaced the line breaks with the <br> tags as you suggested, also changed the Jelly tags so it does not escape them like so:
<table>
<tr>
<td>
<j:set var="jvar_active_note" value="${sysparm_activeNotification}"/>
<g2:no_escape>${HTML:jvar_active_note}</g2:no_escape>
</td>
</tr>
</table>
But the text is still escaping the br tags:
Any idea why it is escaping them? I have also tried the <g:no_escape> tag
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-15-2021 07:41 AM
So far none of these worked:
- <pre> tags
-
${jvar_active_note.getHTMLValue()} (using getHTMLValue() method)
- white-space: pre styling (also tried adding the style inline)
- white-space: pre-line styling (also tried adding the style inline)
- <g2:no_escape> tag
- <g:no_escape> tag
- <j2:whitespace trim="false"> tag
Using all of the above, the string would still ignore the line breaks. Here is what ended up working for me:
- I took the suggestion
@Sandeep Dutta kindly made to replace the line breaks with <br> tags in my Client Script using RegEx:
function invokeMessage(){
//console.log('crisOut');
var c = g_form.getReference('company', function(company){
var an = company.u_active_notification;
var lineBreaks = an.replace(/\n/g, '<br></br>'); //input <br> tags
//console.log('crisAN ' + an);
//console.log('crisAN1 ' + lineBreaks);
if(!an){
//console.log('crisNo ');
return;
}
//console.log('crisYes ');
var gdw = new GlideModal('active_notification', false, 'modal-lg');
gdw.setTitle('Active Notification');
gdw.setPreference('sysparm_activeNotification', lineBreaks); //pass the HTML version to the GlideModal
gdw.render();
});
}
- In the UI Page HTML, I then tried to use the 'getHTMLValue()' method mentioned above, with no luck. The <br> tags were being escaped in the GlideModal.
- The solution:
- In the UI Page Client script I added this Load Event:
addLoadEvent(function(){
var m = GlideModal.prototype.get("active_notification");
var p = m.getPreference("sysparm_activeNotification");
document.getElementById("crisDiv").innerHTML = p; //create div with same id in HTML and set the innerHTML to the preference we grabbed from the Client Script
});
End result: (Spoiler alert! We have the line breaks!):
I was very close to giving up on this; So many things that would work in a regular HTML implementation (such as the <pre> tags) did not work on UI Page. Did not think something as simple as just showing the line breaks from a string field would have been so difficult!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-14-2023 04:35 AM - edited ‎02-14-2023 04:37 AM
Hi @Cris P and everyone else dropping by.
I know this is an old post, but in case someone else comes across, wondering how to do this (like me), I wanted to share a much more simple solution.
I found that simply adding an html tag inside the setPreference method enabled you to add additional html tags, like the <br></br>:
glidemodal.setPreference("title", "<html> your text here followed by a line break<br></br>more of your text here</html>");
Maybe there are even smarter tags.. I'm not an html expert, but this did the trick for me.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-05-2025 12:52 AM
Solution is very simple, add
E.g.
<tr>
<td class="section-header border-bottom border-left border-right" colspan="12" valign="top">
<p class="margin-0">Impact:</p>
</td>
</tr>
<tr style="height: 14.25pt;">
<td class="value-cell border-bottom border-left border-right" colspan="12" valign="top" style="white-space:pre-line">
<p class="text-black">
${gs.getMessage('{0}',[incidentGr.getDisplayValue('business_impact')])}
</p>
</td>
</tr>