Need to remove the user name from change approver field once the user is off-boarded
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2024 10:12 PM
Hi Team,
Is there any feasibility, so that once the user (sys_user) is disabled in service now his name should also get removed from the change approver list of sys_user_group table. Any possibilities to automate this process?
REgards,
Sofiya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2024 01:03 PM
No, no OOTB way is available to remove a user from sys_approval table once the approval has been generated. Once an approval trigger it get attached and also as per it will be good customization and increase the technical debt. Also, other than change manager NO can approve a change request on other behalf ( except delegates), so in this, better to remove the user from group once he/she off boarded and in next change No approval will trigger for that user.
Hope it clear way. Share inputs /feedback.
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2024 04:59 PM
Hi @Sofiya Perumal ,
I think the approach you should follow should be similar to the one shared by Sonam in the below thread.
Create a Scheduled Job for daily run
1. to check the inactive user and update the approval records to cancelled
2. Remove the user from the group.
Also please run a fix script for the existing records for the first time as the count would be large. post that schedule job should perform fine.
Script can be similar to the below-
var userGR = new GlideRecord('sys_user');
userGR.addQuery('active', false);
userGR.query();
while (userGR.next()) {
cancelApprovals(userGR.sys_id);
removeFromGroups(userGR.sys_id);
}
function cancelApprovals(userId) {
var approvalGR = new GlideRecord('sysapproval_approver');
approvalGR.addQuery('approver', userId);
approvalGR.query();
while (approvalGR.next()) {
approvalGR.state = 'cancelled';
approvalGR.update();
}
}
function removeFromGroups(userId) {
var groupMemberGR = new GlideRecord('sys_user_grmember');
groupMemberGR.addQuery('user', userId);
groupMemberGR.query();
while (groupMemberGR.next()) {
groupMemberGR.deleteRecord();
}
}
Please modify the script as per your need. You can put appropriate filters as well.
If my response has resolved your query, please consider giving it a thumbs up and marking it as the correct answer!
Thanks & Regards,
Sanjay Kumar