How to get the last comment

SNOW39
Tera Expert

we are sending a notification when the RITM is complete. The body should have the last comment in the body without timestamp.

How can i achieve this?

10 REPLIES 10

am looking for comments not worknotes!

Manish Vinayak1
Tera Guru

The solution suggested by Omkar and others should work if the field name is work_notes and the label is "Work Notes". Just wanted to check are you trying to retrieve the last work notes added or the last additional comments added to the RITM? If it is additional comments, you will need to tweak the code accordingly.

Also, I am assuming you already have the email script to get the comments printed in your email notification; would you be able to share the code written in the email script? That would help people to suggest you changes.

Thanks,

Manish

i am looking for comments not worknotes

Create a Notification Email Script (mail script), use the following code:

 

var commentsArr = current.comments.getJournalEntry(1).split("\n");
commentsArr.shift();
template.print(commentsArr.join("\n"));

 

Then refer your email script in your notification content, using {$mail_script:your_mail_script_name_goes_here}

 

Refer to the documentation https://docs.servicenow.com/bundle/london-servicenow-platform/page/script/server-scripting/concept/c... for more details on using mail script.