Schedule job to cancel RITM if approval is pending with Inactive approver
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2020 01:09 AM
Hi All,
I have a requirement where I have to create a job which runs daily to check all such approvals which are pending with inactive approvers. Below condition should be checked:
1)Approval is in 'requested' state and is pending with Inactive user
2)This is the only approval triggered in the RITM. This should not be a part of group approval.
3)In case this is the only User approval triggered in the RITM, then this approval should be set as 'Cancelled' and the corresponding RITM also set as 'Closed Incomplete'. User should get a notification that request has been 'Closed incomplete' as approver is no longer in system, please raise new request.
Please help on this
--
Thanks,
Geeta Dhami
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2020 11:07 PM
Hi Geeta,
I forgot to use addQuery(); updated script now; please check
var approvalAgg = new GlideAggregate('sysapproval_approver');
approvalAgg.addEncodedQuery('approver.active=false^state=requested^groupISEMPTY');
approvalAgg.addAggregate('COUNT','sysapproval');
approvalAgg.query();
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2020 04:10 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2020 04:57 AM
Hi Geeta,
So you are saying it is going inside while but printing undefined for line 15?
also please convert gs.log to gs.info
Can you add row Count after line 11
gs.info('Row Count is: ' + approvalAgg.getRowCount());
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2020 05:34 AM
Hi Ankur,
I have modified the code as below to get these things and testing for scenario where a RITM has two user approvals in requested state(one with inactive user and other with active user)
1)To get a RITM where approver is inactive. Once this is checked the code will move inside while loop(line 11).
It is going inside that (Correct)
Now I have to check if for this RITM there is only 1 approval triggered.
Again I have done Glide Record and pass that RITM and other condition.Line no 19 is to get the count.
Here for the sample RITM i have two rows which are requested for approval(1 to inactive user and other to inactive user)
Line no 21 should give me count value as 2, but it is giving me count as 1.
Please suggest, where I am going wrong.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2020 06:05 AM
Hi Geeta,
you should update it as below
var count_gr = new GlideRecord('sysapproval_approver');
count_gr.addEncodedQuery('state=requested^groupISEMPTY');
count_gr.query();
var count = count_gr.getRowCount();
gs.info('Hi' + count);
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader