logo

NJP

Multi-line comments in notification template

Import · Oct 29, 2020 · article

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[i] + '');

}

2020-10-28 20:42:16 PDT - System Administrator (Additional comments)

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.

View original source

https://www.servicenow.com/community/itsm-articles/multi-line-comments-in-notification-template/ta-p/2309569