Send a notification when a group is empty

Jesus Nava
Tera Guru

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.

JesusNava_2-1679682497758.png

 

2. This is the event that will trigger the notification:

JesusNava_1-1679682374610.png

 

3. Created Business rule that will trigger the event so that the notification is sent, here is the condition:

JesusNava_3-1679682593581.png

and here is the advanced script:

JesusNava_4-1679682642595.png

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

 

 

2 ACCEPTED SOLUTIONS

AnveshKumar M
Tera Sage
Tera Sage

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

Thanks,
Anvesh

View solution in original post

Elijah Aromola
Mega Sage

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.

View solution in original post

5 REPLIES 5

Thank you Elijah!