Help needed with journal field comments in an email notification.

LK11
Mega Expert

Hi,

I'm trying to display the latest comments from a request in an email notification.  Below is my email script.

var comments = current.comments.getJournalEntry(1);
template.print (comments);

Below is the screenshot of how the comments are displayed in the email.

find_real_file.png

How can I get rid of the date, name and I don't know where  (Comments) is coming from which I don't want either.  If anyone had this issue before, please let me know how you resolved it.

 

Many thanks

6 REPLIES 6

Hi Lk,

Can you use split("\n\n") and try it once.

Regards

Ankur

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

Nikhil Dixit
Giga Expert

Hi there,

You can create your own function to query sys_journal_field and to get the desired value from the journal field. Please find the piece of code which was run through background-script along with its output :

---------------------------------------------------------------------------

var journalEntry = new GlideRecord('sys_journal_field');

journalEntry.addQuery('element', 'comments'); //Provide name of the journal field, here the field name is 'comments'

journalEntry.addQuery('element_id', 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'); //Provide sys_id of the record on which the journal field is present, i.e, sys_id of the change request

journalEntry.query();

while(journalEntry.next()) {

gs.print('Comment : ' + journalEntry.value);

gs.print('Commented By : ' + journalEntry.sys_created_by);

gs.print('Commented On : ' +journalEntry.sys_created_on + '<hr>');

 

}

 

---------------------------------------

Output :

 

*** Script: Comment : Comment#1 <-- Comment by user
*** Script: Commented By : User#1 <-- User ID of the user
*** Script: Commented On : xxxxxx


*** Script: Comment : Comment#2
*** Script: Commented By : User#2
*** Script: Commented On :xxxxxxxx


*** Script: Comment : Comment#3
*** Script: Commented By : User#3
*** Script: Commented On : xxxxxxxxxxx

 

Please mark answer correct or helpful based on the response.

-- 

Warm Regards

Nikhil Dixit

Engineer

t

www.DxSherpa.com | Skype : nnikkhil2709dixit |