Copy approval comments to SCTASK work notes

psyherin
Kilo Sage

Hi All,

I need to copy approver comments to SCTASK work notes and below is script added to the WF when catalog task is created. I have followed the https://community.servicenow.com/community?id=community_question&sys_id=9e9bcb61db9cdbc01dcaf3231f96...

The approver comments are copied over sctask but it is copying multiple times and I am trying to get my head around why it is doing that. There are multiple approvers on the RITM and once it is approved it should copy the approver comments to sctask work notes. Am I missing something here?

var apv = new GlideRecord('sysapproval_approver');
apv.addQuery('sysapproval', current.sys_id);
apv.addQuery('comments', '!=', ''); // Only find approvals that have comments on them
apv.query();

while (apv.next()) { // Go through all approvals with comments
    task.work_notes += "\nApproval Comments: from " + apv.approver.name + "\n" + apv.comments.getJournalEntry(-1);
}

find_real_file.png

find_real_file.png

 

Any help is appreciated.

Thank you.

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

update as this

var arr = [];
var apv = new GlideRecord('sysapproval_approver');
apv.addQuery('sysapproval', current.sys_id);
apv.addQuery('comments', '!=', ''); // Only find approvals that have comments on them
apv.query();
while (apv.next()) { // Go through all approvals with comments
	arr.push("Approval Comments: from " + apv.approver.name + "\n" + apv.comments.getJournalEntry(-1));
}
task.work_notes = arr.join('\n');

regards
Ankur

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

View solution in original post

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

update as this

var arr = [];
var apv = new GlideRecord('sysapproval_approver');
apv.addQuery('sysapproval', current.sys_id);
apv.addQuery('comments', '!=', ''); // Only find approvals that have comments on them
apv.query();
while (apv.next()) { // Go through all approvals with comments
	arr.push("Approval Comments: from " + apv.approver.name + "\n" + apv.comments.getJournalEntry(-1));
}
task.work_notes = arr.join('\n');

regards
Ankur

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

It worked!!.

Thank you @Ankur Bawiskar as always. Really appreciate it !!!