You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Scheduled Job: Deactivate Inactive Users and Notify Managers
2
+
3
+
Overview
4
+
This scheduled job automatically deactivates inactive users based on their last login time and creation date, and sends an email notification to their active manager using the ServiceNow event framework (gs.eventQueue()).
5
+
6
+
The entire process is divided into three components:
7
+
1.Scheduled Job Script — Finds inactive users and fires an event.
8
+
2.Event Registration — Registers user.deactivation.notify_manager in the Event Registry.
9
+
3.Script Action — Sends an email to the manager dynamically.
10
+
11
+
1. Scheduled Job Script
12
+
13
+
Purpose
14
+
This script runs on a schedule (e.g., daily or weekly) and:
15
+
Finds users who haven’t logged in for a specific number of days.
16
+
Checks their account creation date.
17
+
Deactivates those users.
18
+
Fires an event to notify their manager if the manager is active.
19
+
20
+
Logic Summary
21
+
Calculates a cutoff date (e.g., 90 days of inactivity).
22
+
Queries sys_user for users:
23
+
Whose last_login_time is older than the cutoff date OR is empty.
24
+
Whose sys_created_on is older than the cutoff date.
25
+
Who are currently active.
26
+
For each matching user:
27
+
Finds their manager record.
28
+
Checks if the manager is active.
29
+
Deactivates the user.
30
+
31
+
Sends an event with:
32
+
parm1: User name
33
+
parm2: Manager’s email
34
+
35
+
2. Event Registration:
36
+
37
+
Name: user.deactivation.notify_manager
38
+
Table: sys_user
39
+
Description: “Triggered when a user is deactivated due to inactivity.”
0 commit comments