- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2024 09:40 AM
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
_______________________________________________________
_______________________________________________
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2024 02:30 PM
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, '');
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2024 09:54 AM - edited 09-26-2024 09:55 AM
var usr = new GlideRecord('sys_user');
usr.addQuery('last_login', '<', gs.daysAgo(90));
usr.query();
while (usr.next()) {
gs.info('User ' + usr.name + ' last_login ' + usr.last_login);
}
works in my instance. Add another 'addQuery(); if you like. Queue the event in the 'while' loop.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2024 10:13 AM
Hi,
If we user "usr.addQuery('last_login', '<', gs.daysAgo(90));" the notification will keep send to the user start from 91. We would like to inform the user only once.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2024 12:19 PM - edited 09-26-2024 01:15 PM
You make the user in-active, then add
var usr = new GlideRecord('sys_user');
usr.addQuery('last_login', '<', gs.daysAgo(90));
usr.addQuery('active', true); // only look for active users
usr.query();
while (usr.next()) {
gs.info('User ' + usr.name + ' last_login ' + usr.last_login);
usr.active = false;
usr.update();
}
Or just have your scheduled job run weekly, before making the user account in-active.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2024 02:30 PM
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, '');
}