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-04-2023 02:21 AM
It is returning the value marked in yellow tick "Test" but I want the latest one "Test Again" to get returned.
Thanks and Regards,
Saurabh Chatterjee
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2023 03:25 AM
getJournalEntry(1)
is meant to give you latest comment, use it with comments as field.
gr1.comments.getJournalEntry(1)
I have tested it on PDI and it worked for me. try testing on new task . Do share the script screenshot if that didn't work.
Regards,Sushant Malsure
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2023 02:56 AM
why not query sys_journal_field and pick the latest value for your record and fieldname?
var fieldName = 'comments';
var latestValue;
var rec = new GlideRecord('sys_journal_field');
rec.orderByDesc('sys_created_on');
rec.addQuery('name', 'tableName');
rec.addQuery('element', fieldName);
rec.addQuery('element_id', this.getParameter('sysparm_roleID'));
rec.setLimit(1);
rec.query();
if(rec.next()){
latestValue = rec.value;
}
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(latestValue);
}
return JSON.stringify(arr);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader