Varun30
Giga Expert

One of the requirement I was working on in Servicenow was to generate a notification when an RITM is commented. The issue was as follows:

When user enters multi-line comment on RITM for example:

"This is a test

This comment is on line 2"

I used an email script to add notification as:

template.print(current.comments.getJournalEntry(1))

This statement gives the latest comment on an RITM. 

On my notification, this comment above was displayed as:

2020-10-28 20:42:16 PDT - System Administrator (Additional comments) This is a test This comment is on line 2
 
The approach I used in this case is the mail script:
 
Step 1: Get the latest comment
var comment = current.comments.getJournalEntry(1);
 
Step 2: Split the comment by new line
var notes = comment.split("\n");
 
Step 3: Display each line using for loop along with template
for(var i=0;i<notes.length;i++){
      template.print('<div><font color="#4d148c" face="Segoe UI">' + notes[i] + '</font></div>');
}
 
The required output is:
2020-10-28 20:42:16 PDT - System Administrator (Additional comments)
This is a test
This comment is on line 2
 
Ensure that the newlines to html tag is unchecked.
You can now use this mail script in your notification.
 
These multi-line comments template can be confusing if you are new to ServiceNow. Please mark the article useful if this helped you in any way.
Comments
Ramu6
Tera Contributor

Hi Varun

can we exclude this line"2020-10-28 20:42:16 PDT - System Administrator (Additional comments)" from comments ?

Thanks and Regards

Ramu k

Varun30
Giga Expert

I don't think so. 

Rajkumar Sakthi
Kilo Expert

Hi Ramu,

you can skip the first line in the for loop.

alternatively, you can change the font color as well. so that it will be hidden.


	template.print('<div style="color: #FFF;">' + notes[0] + "</div>");
	template.print('<strong><div style="color: darkorange;">');

	for(var i=1;i<notes.length;i++){
		template.print(notes[i]); 
	}

 

Regards

S Rajkumar

Version history
Last update:
‎10-28-2020 11:05 PM
Updated by: