Deactivate users not logged in for last 60 days

Gagandeep2
Mega Contributor

I need to deactivate the users who have not logged it for the last 60 days. The system should check for it everyday at midnight and deactivate the users.

 

@asifnoor  please reply.

1 ACCEPTED SOLUTION

asifnoor
Kilo Patron

Hi,

You can create a scheduler with type script of your choosing and add below code. 

var gr = new GlideRecord("sys_user");
var gdt = new GlideDateTime();
gdt.addDays(-60);
gr.addQuery("last_login_time","<=",gdt);
gr.addActiveQuery();
gr.query();
gr.active=false;
gr.updateMultiple();

Mark the comment as a correct answer and helpful if it helps.

 

View solution in original post

3 REPLIES 3

sachin_namjoshi
Kilo Patron
Kilo Patron

Configure flow designer flows and you can schedule this flow every night to make user inactive if they don't logged in from last 60 days.

 

https://docs.servicenow.com/bundle/orlando-servicenow-platform/page/administer/flow-designer/concept...

 

Regards,

Sachin

asifnoor
Kilo Patron

Hi,

You can create a scheduler with type script of your choosing and add below code. 

var gr = new GlideRecord("sys_user");
var gdt = new GlideDateTime();
gdt.addDays(-60);
gr.addQuery("last_login_time","<=",gdt);
gr.addActiveQuery();
gr.query();
gr.active=false;
gr.updateMultiple();

Mark the comment as a correct answer and helpful if it helps.

 

Purushothaman 1
Mega Explorer

Hi,

This script was useful and works. can you please provide the roll back script aswell.

Thanks.