- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2023 11:31 AM
Hello experts, there is a group called "testers" users can add themelves or remove themselves from that group. When the group has no members or gets empty, a notification needs to be sent to the managers notifying that the "testers" group is empty.
I tried the followimg:
1.Created a notification using the sys_user_grmember table and triggered by event.
2. This is the event that will trigger the notification:
3. Created Business rule that will trigger the event so that the notification is sent, here is the condition:
and here is the advanced script:
when I tested it, I removed all users from the group but the notification was not sent, where am I wrong? could you help me correct it?
Thank you
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2023 11:52 AM
Hi @Jesus Nava,
In the business rule, when to run, remove the condition User is Empty and change the trigger to Delete instead of Update.
Then in the script, add the following code,
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group', current.group);
gr.query();
if(!gr.next()){
gs.eventQueue('test.group.empty');
}
Try this.
Thanks,
Anvesh
Anvesh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2023 11:55 AM
Your "when to run" needs to be changed to update and delete. Remove the "user" part of the condition. The script will have to query that table again to see if there any users left in it, if not, send the notification.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2023 11:51 AM
Your problem is with step 3. sys_user_grmember is a relation between the group table and user table. There shouldn't be rows where group is 'Testers' and user is empty.
You would need a business rule on the sys_user_grmember table that runs when a record with group = 'testers', is deleted. It would then create an event if no other records where group = 'testers' exist.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2023 11:52 AM
Hi @Jesus Nava,
In the business rule, when to run, remove the condition User is Empty and change the trigger to Delete instead of Update.
Then in the script, add the following code,
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group', current.group);
gr.query();
if(!gr.next()){
gs.eventQueue('test.group.empty');
}
Try this.
Thanks,
Anvesh
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2023 12:05 PM
Thank you it worked this way!
Warm Regards

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2023 11:55 AM
Your "when to run" needs to be changed to update and delete. Remove the "user" part of the condition. The script will have to query that table again to see if there any users left in it, if not, send the notification.