Scheduled Job - Query users that has the last login 91 days from today

hongsok
Tera Contributor

Hi Friends,

 

I have created the following Scheduled Job to run daily to find out who has not login for 91 days and send them the email notification. It is not working. I would appreciate if you can help me on this.

 

Regards,

Hong

_______________________________________________________

var gr = new GlideRecord('sys_user');
gr.addNotNullQuery('last_login');
//gr.addEncodedQuery('active=false^u_account_request_numberISNOTEMPTY');
gr.query();
var gdt = new GlideDateTime();
gdt.addDaysUTC(-91);
while (gr.next()) {
    if (gr.getValue('last_login') == gdt.getLocalDate()) {
        gs.eventQueue('user.account.deactivated', gr, '');
    }
}

_______________________________________________

 

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

Run something like this as a Fix Script to see the results vs what is expected, then adjust the numbers if needed before disabling the print line and uncommenting the eventQueue for your scheduled script.  In a PDI or non-prod instance you should be able to update Last login in a list view to test the results.

var userGr = new GlideRecord('sys_user');
userGr.addEncodedQuery('last_login!=NULL^last_loginRELATIVELT@dayofweek@ago@89^ last_loginRELATIVEGT@dayofweek@ago@91');
userGr.query();
while (userGr.next()) {
	gs.print(userGr.name); //temporary for troubleshooting
    //gs.eventQueue('user.account.deactivated', gr, '');
}

View solution in original post

5 REPLIES 5

hongsok
Tera Contributor

Hi Kilo,

I made a small change and it works - Thanks

 

var usr = new GlideRecord('sys_user');
usr.addNotNullQuery('last_login')
usr.addEncodedQuery('active=true^u_account_request_numberISNOTEMPTY^last_loginRELATIVELT@dayofweek@ahead@90^last_loginRELATIVEGT@dayofweek@ago@92');
usr.query();
while (usr.next()) {
    gs.eventQueue('user.account.deactivated', usr, '');
}