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-14-2021 05:51 AM
Hi,
HTML will remove line breaks by default. If you want line break then you need to replace all line break with br tag.
Otherwise easy option is to include a pre tag. Pre tag will not omit line breaks
<j:set var="jvar_active_note" value="${sysparm_activeNotification}"/>
<p class="modal-title h4 modal-header"><pre>${jvar_active_note}</pre></p>
Palani
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-15-2021 01:36 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-14-2021 06:01 AM
Hi Cris,
transfer the value to the <style> tag as next,
<tr>
<td style="white-space:pre-line">
${jvar_street}
</td>
</tr>
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 01:44 AM
Hi Sandeep,
Thanks for your reply; I have tried setting the inline style to the same 'white-space:pre-line', but this has no effect and the string does not preserve the line breaks