Client Script not showing variable message on new line

Prudhvi Potru
Tera Contributor

In a client script, I’m trying to display a message on a variable field with line breaks (using <br> or \n). But the message appears in a single line. Is there a ServiceNow-supported way to render messages with new lines or styled HTML in catalog items?

Instead on writing 3 new g_form.showMessage('cc', 'My message');
is there any way to insert a new line in long description?

5 REPLIES 5

Prudhvi Potru
Tera Contributor

PrudhviPotru_0-1751888181534.png

 

Dnyaneshwaree
Mega Sage

Hello @Prudhvi Potru ,


Have you used " g_form.showFieldMsg('your_variable_name', 'message1', 'message2',...);" ?if not please try this if you want msg exact below the variable. It will display witout HTML

If want HTM Tags, You can use g_form.addInfoMessage() or g_form.addErrorMessage() to display messages at the top of the catalog item form. As it supports HTML.

 
function onLoad() {
  var message = 'This is a first Message.<br>This is the <b>second</b>Message.';
  g_form.addInfoMessage(message);
}
Please accept my solution if it works for you and thumps up to mark it as helpful.
Thank you!!

Dnyaneshwaree Satpute
Tera Guru

Ankur Bawiskar
Tera Patron
Tera Patron

@Prudhvi Potru 

g_form.showFieldMsg() doesn't support HTML tags such as <br/> so you cannot add new line.

the only way is to use g_form.showInfoMessage() where you can add HTML tags

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Prudhvi Potru 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader