Business Rule to copy approval/approver comments to the Requested Item

alhicks
Tera Guru

I found a script on the forum for the workflow after the approval and it seems to be working but we'd like to setup a Business Rule instead to update the RITM with the Approver Comments. We have some that reply to the email to approve and then minutes later reply back with comments. The workflow script doesn't capture the new comments if they've already approved. We want to update the RITM anytime comments are added to the approval.

This is the run script in the Workflow on the sc_req_item table.

var app = new GlideRecord('sysapproval_approver');
var qc1 = app.addQuery('sysapproval', current.sys_id);
var qc2 = app.addQuery('state', 'approved');
qc2.addOrCondition('state', 'rejected');
app.query();

while (app.next()) { // change if to while so it will go through all approvals with comments
current.u_approver_comments += "\nApprover Name: " + app.approver.name; // add approver name here
current.u_approver_comments += "\nApproval Status: " + app.state;
current.u_approver_comments += "\nApprover Comments: " + app.comments;
current.u_approver_comments += "\n----------------------------------------";

}

2 REPLIES 2

Akshya
Tera Expert

This is the one I wrote for copying Approvers comments to Change Request. You can modify this for RITM.

Table - sysapproval_approver
When - after
Insert, Update
Filter - Comments Changes

Script - 

(function executeRule(current, previous /*null when async*/) {

var gr= new GlideRecord('change_request');
gr.get(current.getValue('sysapproval'));
gr.work_notes=current.comments.getJournalEntry(1);
gr.update();
})(current, previous);

Let me know if it helps. 

Thanks,
Akshya

rajesh9885
Mega Guru

Try this

Tyr this.

(function executeRule(current, previous /*null when async*/) {
var user = current.approver.name;
var sr = new GlideRecord('sc_req_item');
sr.get(current.sysapproval);
sr.comments = "Comment copied from approval record:\n" + "Approver :-" +user+ " " +current.state+" " +"your request and added following comment :\n\n" +current.comments.getJournalEntry(1);  // change the comment as you desire
sr.update();

})(current, previous);