getJournalEntry() to return the latest comment added - script logic not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2023 09:50 AM
Hi All,
Through a script include, I am trying to return the latest journal entry but it is not working. Can someone please help to correct the script?
var arr = [];
var gr1 = new GlideRecord('table');
gr1.addQuery('sy_id', this.getParameter('sysparm_roleID'));
gr1.query();
if (gr1.next()) {
arr.push(gr1.getDisplayValue('role_title'));
arr.push(gr1.level.getDisplayValue());
arr.push(gr1.comment.getJournalEntry(-1)); //Comment is the field name which is journal type; Not Working
}
return JSON.stringify(arr);
Thanks and Regards,
Saurabh Chatterjee
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2023 10:08 AM
I have corrected the code a bit try it.
var arr = [];
var gr1 = new GlideRecord('table'); // have correct table name instead of 'table' here
gr1.addQuery('sys_id', this.getParameter('sysparm_roleID')); //sys_id is correct field name
gr1.query();
if (gr1.next()) {
arr.push(gr1.getDisplayValue('role_title'));
arr.push(gr1.level.getDisplayValue());
arr.push(gr1.comments.getJournalEntry(-1)); //correct field name is comments not comment
}
return JSON.stringify(arr);
have added comment above where your input needed and places where i corrected
Regards,Sushant Malsure
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2023 01:05 AM
Hi @sushantmalsure ,
Thank you for your reply!
It worked by adding 'comment' only. But the challenge is, it is returning all the comments but I only need the last comment.
Thanks and Regards,
Saurabh Chatterjee

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2023 01:10 AM
Hello you need to use getJournalEntry(1) instead of -1
getJournalEntry(1) gets the latest entry.
getJournalEntry(-1) gets all entries.
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2023 01:17 AM
then use '
gr1.comments.getJournalEntry(1))
'
Regards,Sushant Malsure