Skip to content

Commit 5760467

Browse files
authored
Create Disable Service accounts due to inactivity
This schedule job script will help to auto disable the service accounts which has not been logged in or used for last 40 days.
1 parent 12c8338 commit 5760467

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
var user = new GlideRecord("sys_user"); // Glide to user table
2+
user.addActiveQuery();
3+
user.addEncodedQuery("u_service_account=true"); // Adding encoded query to filter the only Service Account
4+
user.query();
5+
while (user.next()) {
6+
var arr = []; // Definind an empty array
7+
arr.push(user.user_name); // pushing all he usernames with in the array
8+
for (var i = 0; i <= arr.length - 1; i++) {
9+
var userID = arr[i];
10+
var query1 = "sys_created_onRELATIVELT@dayofweek@ahead@40^sys_created_by=" + userID; // creating a dynamic query to check if the account has any transaction in last 40 days on transaction table.
11+
var tranSaction = new GlideRecord("syslog_transaction"); // Glide to the tranaction table
12+
tranSaction.addEncodedQuery(query1); // adding an query1
13+
tranSaction.query();
14+
tranSaction.orderByDesc("sys_created_on");
15+
if (!tranSaction.next()) {
16+
gs.print(arr); // this will print only user names which does not have any transaction in last 40 days on log transaction table.
17+
}
18+
}
19+
}

0 commit comments

Comments
 (0)