- 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-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-03-2020 10:17 AM
Hi,
Thats because the record is being deleted and hence in the notification the record does not exist.
I suggest that you create another event and trigger than event in the mail script of your notification and write a script action which listen to this event and delete the record there.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2020 10:38 AM
Hi Noor,
can you please explain briefly because i have created one script which are removing the user from group but notification is not triggering because event is triggering at same time. How i can differentiate the time for event first will go notification than user will remove.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2020 11:16 AM
Hi,
Here is how you should do
1. create 1 more event on sys_user_grmember table.
2. Create a script action and listen to this event and add code liek this
current.deleteRecord();
3. then from your scheduled script remove deleteRecord line
4. Go to your notification and add a mail script
in the mail script trigger the newly created event.
This way, once the notification is fired, then your Script action will execute and delete the record.
Mark the comment as a correct answer and also helpful once worked.