How to disable a user if the last login time is greater than 90 days

Raghesh
Giga Expert

Hi,

We have a requirement to disable or deactivate the users in ServiceNow if their last login time is greater that 90 days.

Is this something which we can do with a script?.

regards,

Raghesh

7 REPLIES 7

Raghesh
Giga Expert

Hi @Ankur Bawiskar ,

Thank you so much for the steps, I will try this and let you know.

 

regards,

Raghesh

@Raghesh 

Sure do keep posted.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards
Ankur

Sayali Gavali1
Tera Contributor

Hi,
You can also use scheduled job for this. Please refer below script:

var gr = new GlideRecord('sys_user');
gr.addActiveQuery();
gr.addEncodedQuery('last_login<=javascript:gs.beginningOfLast3Months()');
gr.query();
while (gr.hasNext()) {
    if (gr.next()) {
        gr.active = false;
        gr.update();
    }
}