How to get approval comments post-approval
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-12-2025 11:04 PM
Hello all,
I need to collect all comments and the actors making the comments (and their decisions). I am using the following script based on
// Get all approvers and comments
var arr = [];
var apv = new GlideRecord('sysapproval_approver');
apv.addQuery('sysapproval', current.sys_id);
apv.query();
while (apv.next()) { // Go through all approvals with comments
arr.push("Approval Comments: from " + apv.approver.name + "\n" + apv.comments.getJournalEntry(-1));
}
var approver_hist = arr.join('\n');
gs.log("Approver History: "+ approver_hist,"RITM Post Approval Info");
The log shows the approver name but not the comments. What am I doing wrong?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-13-2025 02:07 AM
The issue you're encountering where the log shows the approver name but not the comments likely occurs because the getJournalEntry(-1)
method is used incorrectly. The getJournalEntry
method is typically used to fetch a specific journal entry by index, and -1
refers to the latest journal entry. However, this method might not return the expected result if the comments
field is a journal field.
Instead of using getJournalEntry(-1)
, you should access the journal field using the comments
object and iterate through the journal entries to retrieve all comments. Here's how you can modify your script to collect the approver's comments correctly:
// Get all approvers and comments
var arr = [];
var apv = new GlideRecord('sysapproval_approver');
apv.addQuery('sysapproval', current.sys_id);
apv.query();
while (apv.next()) { // Go through all approvals with comments
var comments = apv.comments.getJournalEntries(); // Get all journal entries for the comments field
var approverHistory = "Approval Comments: from " + apv.approver.name;
// Iterate through each comment entry
comments.forEach(function(entry) {
approverHistory += "\n" + entry;
});
arr.push(approverHistory);
}
var approver_hist = arr.join('\n');
gs.log("Approver History: " + approver_hist, "RITM Post Approval Info");
If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!
Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI
ļ YouTube: https://www.youtube.com/@learnservicenowwithravi
ļ LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā01-19-2025 08:59 PM
Hello @Ankur Bawiskar @Ravi Gaurav @lehiyis5
Thank you all for your help. With your help, I was able to capture the comments.
var scReqItemId = current.sys_id;
var arr = [];
var apv = new GlideRecord('sysapproval_approver');
apv.addQuery('sysapproval',scReqItemId);
apv.query();
while (apv.next()) { // Go through all approvals with comments
var approverHistory = "Approval Comments: from " + apv.approver.name;
var commentGr = new GlideRecord('sys_journal_field');
commentGr.addQuery('element_id', scReqItemId);
commentGr.addQuery('element', 'comments');
commentGr.orderBy('sys_created_on');
commentGr.query();
while(commentGr.next()){
approverHistory += commentGr.value.toString();
}
arr.push(approverHistory);
}