- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2020 10:07 AM
A schedule job exists that runs daily at midnight that checks for the last login date of all users with an entitlement role [itil, sn_customerservice_agent, ITBM roles]. If the login date is more than 3 months ago, or if the created date was more than 3 months ago AND last login date is null, remove that user from the groups that are granting them the inherited roles.
Send a notification to any of these groups' manager that they have been removed due to inactivity. Include the user name, email address, and last login date in this email.
created the scheduled job record is delete from group member table but notification is not triggering the group member. But when i removed the deleteRecord() from the script notification is triggering.
Please suggest what needs to do for both action will perform at some time gap.
var inactive = GlideRecord("sys_user");
inactive.addEncodedQuery("roles=ITIL^last_login_time<javascript:gs.beginningOfLast3Months()");
inactive.query();
while (inactive.next()) {
var user = GlideRecord("sys_user_grmember");
user.addQuery("user", inactive.sys_id);
user.query();
while (user.next()) {
gs.eventQueue('Testinggroup', user, user.group.manager);
user.deleteRecord();
}
}
Thanks in advanced.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2020 10:16 AM
Hi Nitin,
You are deleting the record that you send to the Event queue.
Perhaps you can change it to instead of sending user (which is a sys_user_grmember you are deleting) change it to the sys_user?
Make sure to check on which table your notification is as well and update accordingly.
Like this:
var inactive = GlideRecord("sys_user");
inactive.addEncodedQuery("roles=ITIL^last_login_time<javascript:gs.beginningOfLast3Months()");
inactive.query();
while (inactive.next()) {
var user = GlideRecord("sys_user_grmember");
user.addQuery("user", inactive.sys_id);
user.query();
while (user.next()) {
gs.eventQueue('Testinggroup', inactive, user.group.manager);
user.deleteRecord();
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2020 12:40 AM
This is a good Use Case for Flow Designer.
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022