Info Message from description with Line breaks

kapilm
Kilo Contributor

I have a requirement, where I need to show the value from an description field with line breaks as an info message..

for eg:

Description:

Type: String

First Line

Second line

third line

So in info message it should retain the same format, like

First Line

Second line

third line

But, actually it is showing like this "First line second line third line"

Thanks in Advance..

10 REPLIES 10

Did you get any alternate solution?

Alexandre Sing2
Kilo Expert

Insert <BR> instead of \n or <\br> in your message where you need a line break.


Works fine in addErrorMessage.



For your requirement, maybe you should use a variable for your message.


This variable has as input your description, in which your replaced the line breaks by <BR>.



Provide more information on your input : which table/field is it ? If you need more support on how to transform the description into a variable, if this can be done.


GregM1
Tera Contributor

try this:

var controlID = g_form.getControl('other_field_name').id + '_fieldmsg'; //It will give you id of div containing error, warning, info message
g_form.showFieldMsg('other_field_name', g_form.getValue('description_field_name'), 'error'); // here comes the code that shows message
document.getElementById(controlID).style.whiteSpace = 'pre-wrap'; //magic happens here

Astridkm
Giga Contributor

Setting my c.data.description to style="white-space: pre-wrap;" solved my issue perfectly.

Hi, 
I’ve sorted it out this way:

var controlID = g_form.getTableName()+'.' +'u_field_name'+ '_fieldmsg';
g_form.showFieldMsg('u_field_name', msgTrasnlated, 'info'); //I get value previously
document.getElementById(controlID).style.whiteSpace = 'pre-wrap'; //add breaks

Now I want to do the same on Portal form, but "document" does not work on portal.

https://docs.servicenow.com/bundle/paris-servicenow-platform/page/build/service-portal/concept/unsupported_client_scripts.html


Thanks GregM