Journal Field new line is not working through script

neethu4
Giga Expert

Hi All,

I used this below code for adding note in comment field but "\n" is not giving new line in comment field.

Please let me know any issue in this script

var comments_ritm = " This case has been created from "+number;

var comments = current.comments.getJournalEntry(-1);

ca.comments = comments_ritm+"\n\n"+comments;

Thanks,

Neethu

1 ACCEPTED SOLUTION

neethu4
Giga Expert

The issue got fixed by using following script


var number= gs.getMessage(["[code]<a   href =sc_req_item.do?sys_id="+ current.sys_id +">"+ current.number +"</a><p>[code]"]);


var comments_ritm = " This case has been created from "+number;


var comments = current.comments.getHTMLValue();


ca.comments = comments_ritm+comments;


View solution in original post

11 REPLIES 11

Chuck Tomasi
Tera Patron

Hi Neethu,



I just tried the following from scripts background on one of my incidents and it respected the \n\n. Can you verify.



var inc = new GlideRecord('incident');


inc.get('85071a1347c12200e0ef563dbb9a71c1'); // Use a sys_id of one of your test incidents


var com = 'This is a comment\n\nwith multiple lines\n\nwritten in scripts - background\n\n';


inc.comments = com;


inc.update();



If it works, then we know there might be something with your script. More context is appreciated - for example, did you get any errors? Is there more to the script than what is shown? Did it add any comments and just not add the \n\n?


This definitely works!  After scouring the community this did the trick!   Thanks Chuck!

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Neethu,



From where you are updating the comments?


Is it from business rule or some other server side script?




Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


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

I am updating it from UI Action