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.

Latest comment not populating via email script

Arjit Gourav
Tera Contributor

Hello,

 

I am currently trying to populate the latest additional comment added (where any user is tagged with @ mention) of a particular table with help of a custom email script.

 

Notification utilized : Activity Stream Mention Email  (Notification is running on live_notification table)

 

Script used for populating latest comment:

 

var gr=new GlideRecord ('sys_journal_field');

gr.addEncodedQuery("name=tablename^element=comments^element_id"+current.sys_id);

gr.orderByDesc('sys_created_on');

gr.setLimit(1);

gr.query();

if(gr.next()){

template.print("latest comment is"+gr.value);

}

 

Note:- Over the email script, rest of the details like number, subject etc. of the records of the table for the particular @ mention gets populated over email notification.

Kindly assist if anyone has any recommendations/solution to it.

1 REPLY 1

Danish Bhairag2
Tera Sage

Hi @Arjit Gourav ,

 

Instead of doing it this way you can query the actual table where the record is present for eg incident is the table then query the incident table & to fetch the latest comment u can try fetching it like below.

 

 

gr.comments.getJournalEntry(1);

 

 

3.27 getJournalEntry(int)

Gets either the most recent journal entry or all journal entries.

 

Parameters: -1: get all journal entries, 1: get the most recent journal entry.

 

Thanks,

Danish