Skip to content

Commit 921b373

Browse files
Weekly Licensed User Access Review (90-Day Inactivity) (#2496)
* Create Weekly_LicensedUser_Access_Revoke_90Days.js * Create readme.md
1 parent bcb27a8 commit 921b373

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
(function executeWeeklyJob() {
2+
3+
var DAYS_INACTIVE_THRESHOLD = 90; // number of days without login before revocation
4+
var licensedRoles = ['itil', 'sys_approver', 'admin', 'business_stakeholder'];
5+
6+
var roleGroupMap = {
7+
'itil': 'ITIL Group',
8+
'sys_approver': 'Approver Group',
9+
'admin': 'Admin Group',
10+
'business_stakeholder': 'Business Stakeholder Group'
11+
};
12+
13+
var thresholdDate = new GlideDateTime();
14+
thresholdDate.addDaysUTC(-DAYS_INACTIVE_THRESHOLD);
15+
16+
// Iterate through each licensed role
17+
for (var i = 0; i < licensedRoles.length; i++) {
18+
var role = licensedRoles[i];
19+
var groupName = roleGroupMap[role];
20+
21+
var userRoleGR = new GlideRecord('sys_user_has_role');
22+
userRoleGR.addQuery('role.name', role);
23+
userRoleGR.addQuery('user.active', true);
24+
userRoleGR.query();
25+
26+
while (userRoleGR.next()) {
27+
var user = userRoleGR.user.getRefRecord();
28+
var lastLogin = user.last_login_time;
29+
30+
// If user never logged in or inactive beyond threshold
31+
if (!lastLogin || lastLogin < thresholdDate) {
32+
// gs.info('Revoking access for user: ' + user.name + ' (' + role + ')');
33+
34+
// Remove from corresponding group
35+
var groupGR = new GlideRecord('sys_user_grmember');
36+
groupGR.addQuery('user', user.sys_id);
37+
groupGR.addQuery('group.name', groupName);
38+
groupGR.query();
39+
while (groupGR.next()) {
40+
groupGR.deleteRecord();
41+
}
42+
43+
}
44+
}
45+
}
46+
})();
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Weekly Licensed User Access Review (90-Day Inactivity)
2+
3+
# Overview
4+
This scheduled job runs weekly and automatically revokes access for licensed users who have been inactive/last login for more than 90 days.
5+
It ensures license compliance, cost control, and adherence to security policies.
6+
7+
# Objective
8+
To identify active users holding licensed roles who have not logged into ServiceNow within the past 90 days and revoke their access by removing them from their respective groups.
9+
10+
# Configuration Summary
11+
1. Threshold - 90 days since last login
12+
2. Frequency - Weekly
13+
3. Licensed Roles Checked - 'itil', 'sys_approver', 'admin', 'business_stakeholder'
14+
4. Groups Managed - ITIL Group, Approver Group, Admin Group, Business Stakeholder Group

0 commit comments

Comments
 (0)