How to get approval comments post-approval

Sanjay Rallapal
Tera Expert

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 

https://www.servicenow.com/community/itsm-forum/copy-approval-comments-to-sctask-work-notes/td-p/725...

// 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?

6 REPLIES 6

Ankur Bawiskar
Tera Patron
Tera Patron

@Sanjay Rallapal 

where are you writing this script? please share screenshots

are you sure there are comments added by that approver?

if yes then only it will show comments

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Sanjay Rallapal
Tera Expert

SanjayRallapal_0-1736753865172.png

I read on this forum that another approach to try is to read the sys journal field, so I tried the following as well
var apv = new GlideRecord('sysapproval_approver');
apv.addQuery('sysapproval', current.sys_id);
apv.query()
while (apv.next()) {
// Get comments for this approval
var commentGr = new GlideRecord('sys_journal_field');
commentGr.addQuery('element_id', apv.sys_id);
commentGr.addQuery('element', 'comments');
commentGr.orderBy('sys_created_on');
commentGr.query();

while (commentGr.next()) {
var commentInfo = {
approver: approvalGr.approver.getDisplayValue(),
comment: commentGr.value.toString(),
timestamp: commentGr.sys_created_on.getDisplayValue()
};
approvalComments.push(commentInfo);
}
}

 

@Sanjay Rallapal 

please share the complete script.

The above script is looking fine

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@Sanjay Rallapal 

Thank you for marking my response as helpful.

As per new community feature you can mark responses as correct.

If my response helped please mark it correct and close the thread so that it benefits future readers.

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