Skip to content

Commit f7c9c39

Browse files
authored
Disable Service accounts due to inactivity
This is for disabling the Service account due to inactivity
1 parent c97b0e5 commit f7c9c39

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed
Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
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
1+
var user = new GlideRecord("sys_user");
2+
user.addActiveQuery();
3+
user.addEncodedQuery("last_login!=NULL");
44
user.query();
55
while (user.next()) {
6-
var arr = []; // Definind an empty array
7-
arr.push(user.user_name); // pushing all he usernames with in the array
6+
var arr = [];
7+
arr.push(user.last_login);
88
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.
9+
var time = arr[i];
10+
var date1 = new GlideDate();
11+
date1.setValue(time);
12+
var date2 = new GlideDate();
13+
var millisecondsDifference = date2.getNumericValue() - date1.getNumericValue();
14+
var daysDifference = millisecondsDifference / (1000 * 60 * 60 * 24);
15+
var days = Math.floor(daysDifference);
16+
if (days > 30) {
17+
user.active = false;
18+
user.locked_out = true;
19+
user.update();
1720
}
21+
1822
}
23+
24+
1925
}

0 commit comments

Comments
 (0)