Deactivate users if not logged for 90 days and check if the users has any opened tickets

Shankar Manohar
Mega Guru

Hi All,

 

I need assistance in scheduled job script to inactivate users who didn't log into system for 90 days and make them inactive. Also, check if the users inactivated has any opened tickets(Task Table), if yes create an incident to a dedicated group.

 

Can someone assist with the script please?

 

 

Thanks

Shan

 

 

6 REPLIES 6

Rafael Batistot
Kilo Patron

Hi @Shankar Manohar 

 

In sys_user there is a field call “last_login” 

 

See the script structure 

 

var grUser = new GlideRecord('sys_user');

    grUser.addQuery('active', true); // only active users

    grUser.query();

 

    var now = new GlideDateTime();

 

    while (grUser.next()) {

        if (grUser.last_login) { // check if the user has ever logged in

            var lastLogin = new GlideDateTime(grUser.last_login);

            var daysInactive = GlideDateTime.subtract(now, lastLogin).getNumericValue() / (1000 * 60 * 60 * 24); // convert ms to days

 

            if (daysInactive >= 90) {

// your logic here 

                }
}

If you found this response helpful, please mark it as Helpful. If it fully answered your question, consider marking it as Correct. Doing so helps other users find accurate and useful information more easily.

GlideFather
Tera Patron

Hi @Shankar Manohar 

 

don't forget to include following conditions:

  • web service access only = false,
  • internal integration user = false.

GlideFather_0-1755104315156.png

 

———
/* If my response wasn’t a total disaster ↙️ drop a Kudos or Accept as Solution ↘️ Cheers! */