- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-14-2023 05:57 AM
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();
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-17-2023 04:59 AM
@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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-14-2023 07:08 AM - edited ‎04-14-2023 07:08 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-17-2023 04:44 AM
Its still not updating the worknote of ritm may be somthing is wrong with the below line
gr.addEncodedQuery('sys_id='+gr.document_id);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-17-2023 04:59 AM
@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.