Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

how to write field message in new line?

ribka_sarimalla
Kilo Contributor

I want field message to appear like below in a single field message not like double messages.

find_real_file.png

I have tried \n, <br>,<BR> but no use. Please suggest.

12 REPLIES 12

Kajal Goti
Mega Guru

Hi,

 

Can you please provide more information where you are writing this ?

 

Can you please provide your code?

var msg="Hello World "+"\n"+"How Are you";

this is how we can use "\n" for new line

 

Please mark as correct/helpful, If you find any help

Hi Kajal,

I am writing this on on-change client script - below is the script

var message_text = 'line1' + '\n' + 'line2' + '\n' + 'examples :' + '\n' + 'line3' + '\n' + 'line4';
var controlID = g_form.getControl('variable').id + '_fieldmsg'; 
g_form.showFieldMsg('variable', message_text, 'info'); 
document.getElementById(controlID).style.whiteSpace = 'pre-wrap';

this is working fine in native view, but showing error in portal.

Hi,

DOM manipulation won't work in portal

this line is causing the issue for portal

document.getElementById(controlID).style.whiteSpace = 'pre-wrap';

Regards
Ankur

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

Hi,

document.getElementById(controlID).style.whiteSpace = 'pre-wrap';  document.getElementById() is a DOM manipulation method to get the element from HTML code with the Id will not workin service portal

 

You can simply use the showFieldMsg() and pass the parameter