The Zurich release has arrived! Interested in new features and functionalities? Click here for more

how to add work note in RITM while rejecting the approval

VIKAS MISHRA
Tera Contributor

As per the below script if any request is not approved till 112 days then we will auto reject that on 13th day and while rejecting the approval we are adding one comment in the approval record but now we want to add the same comment in the RITM record also, but that is not working please suggest how to add the work note in RITM also at the same time.

 

 

 

var gr = new GlideRecord("sysapproval_approver");
gr.addEncodedQuery('sysapproval.numberSTARTSWITHRITM^sysapproval.ref_sc_req_item.cat_item=7c40a1d41b251510680a0e9cdc4bcbf4^state=requested');
gr.addQuery('sys_created_on','<',gs.daysAgo(13));
gr.query();
while (gr.next())
 {
gr.comments = "test comment";
gr.state = 'rejected';
gr.update();
var gr1 = new GlideRecord("sc_req_item");
gr.addEncodedQuery('sysapproval.number=gr1.sysapproval');
gr.query();
 if (gr.next()) {
  gr.comments = 'test comment';
gr.update();
 }
 gr.update();
 }

 

 

 

1 ACCEPTED SOLUTION

@VIKAS MISHRA my bad, I need to tweak the script a bit.

var gr = new GlideRecord("sysapproval_approver");
gr.addEncodedQuery('sysapproval.numberSTARTSWITHRITM^sysapproval.ref_sc_req_item.cat_item=7c40a1d41b251510680a0e9cdc4bcbf4^state=requested');
gr.addQuery('sys_created_on','<',gs.daysAgo(13));
gr.query();
while (gr.next())
 {
gr.comments = "test comment";
gr.state = 'rejected';
gr.update();
var gr1 = new GlideRecord("sc_req_item");
gr1.addEncodedQuery('sys_id='+gr.document_id);
gr1.query();
 if (gr1.next()) {
  gr1.comments = 'test comment';
  gr1.update();
 }

}

Also, this script adds the comments. If you need to add the work_notes then replace comments with work_notes.

View solution in original post

3 REPLIES 3

Sandeep Rajput
Tera Patron
Tera Patron

Here is the updated script, 

 

 

var gr = new GlideRecord("sysapproval_approver");
gr.addEncodedQuery('sysapproval.numberSTARTSWITHRITM^sysapproval.ref_sc_req_item.cat_item=7c40a1d41b251510680a0e9cdc4bcbf4^state=requested');
gr.addQuery('sys_created_on','<',gs.daysAgo(13));
gr.query();
gs.print(gr.getRowCount());
while (gr.next())
 {
gr.comments = "test comment";
gr.state = 'rejected';
gr.update();
var gr1 = new GlideRecord("sc_req_item");
gr.addEncodedQuery('sys_id='+gr.document_id);
gr.query();
 if (gr.next()) {
  gr1.comments = 'test comment';
  gr1.update();
 }

}

 

 

Hope this helps.

Its still not updating the worknote of ritm may be somthing is wrong with the below line

gr.addEncodedQuery('sys_id='+gr.document_id);

 

@VIKAS MISHRA my bad, I need to tweak the script a bit.

var gr = new GlideRecord("sysapproval_approver");
gr.addEncodedQuery('sysapproval.numberSTARTSWITHRITM^sysapproval.ref_sc_req_item.cat_item=7c40a1d41b251510680a0e9cdc4bcbf4^state=requested');
gr.addQuery('sys_created_on','<',gs.daysAgo(13));
gr.query();
while (gr.next())
 {
gr.comments = "test comment";
gr.state = 'rejected';
gr.update();
var gr1 = new GlideRecord("sc_req_item");
gr1.addEncodedQuery('sys_id='+gr.document_id);
gr1.query();
 if (gr1.next()) {
  gr1.comments = 'test comment';
  gr1.update();
 }

}

Also, this script adds the comments. If you need to add the work_notes then replace comments with work_notes.