The CreatorCon Call for Content is officially open! Get started here.

Update RITM "Comments" and Work note fields

Nancy8
Giga Contributor

I am trying   to update both "Comments" and "Work Note" my Requested Item when approver reject,   I used the following script in Run Script of my workflow:

var note ="This Retirement RITM is being rejected as the related change request was not approved" ;

var item = new GlideRecord('sc_req_item');

item.get(current.sys_id);

item.comments =note;

item.work_notes = note;

item.update();

However, both fields are not updated.   Event I did run the following script in Back-ground   script, but it still not works.    

var note ="This Retirement RITM is being rejected as the related change request was not approved" ;

var item = new GlideRecord('sc_req_item');

item.get('896ae660dbe5c7007e94ff621f961985');

//gs.print(item.comments);

item.comments =note;

item.work_notes = note;

item.update();

gs.print(item.comments);

gs.print(item.work_notes);

Can anyone help?

5 REPLIES 5

Bruno De Graeve
ServiceNow Employee
ServiceNow Employee

To update the REQ comments with the approval comments, you can write a onbefore BR on the sysapproval_approver table with a Filter Condition "State changes to Rejected"

and a script:

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

// Copy the comments content to task table
var rec = new GlideRecord('task');
rec.addQuery('sys_id',current.document_id);
rec.query();

if (rec.next()) {
rec.comments.setJournalEntry(current.document_id.getDisplayValue()+" rejected with the following reason: " + current.comments);
rec.update();
}

})(current, previous);

Bruno De Graeve,
Principal Platform Architect, Customer Success, ServiceNow