- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2020 09:26 AM
I want to send notification to group manager only once if we added/removed number of users as group's member.
For example :
1. If i have added 4 users as group member then it should only trigger one notification to group manager and if added 4 more then also it should trigger one notification only.
2. If we removed 2 then also it will trigger one notification.(Right now its triggering for each user addition/deletion.)
Any help is appreciated.
Thanks,
Vinay
Solved! Go to Solution.
- Labels:
-
Notifications
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2020 01:00 PM
Yeah, I tried it without the time restriction, and still couldn't get it to not add the second event, or even change the State so that it didn't trigger the notification, so it's probably best to get rid of that business rule and let the events get added.
I hope I'm not leading you down another rabbit hole, but I stumbled upon something that seems to be getting us closer. In your business rule that is calling the event on deletion, change the call to this
gs.eventQueue('group.membership.delete', current, current.group.name, current.user.name, 'group.membership.delete');
That last parameter will put it into a queue so it won't process. Incidentally, without this I was seeing the event error out and the notification not trigger since it was trying to process on a record that no longer exists, which makes sense I guess. In any event, now we haven't done anything to trigger a notification, but we have captured each name (or ID, or whatever you want) that was deleted from each group, and the date/time stamp, so that seems like progress.
Does the group manager need to get the notification right away? If not, you could have a scheduled job that runs nightly against the sysevent table and pushes all of the names into an array for each group for that day, then calls a new event which is what would cause the notification to trigger. The scheduled job would change the state and/or the queue so that they don't get picked up the next time, so you could run it every hour or whatever and not mess with time ranges.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2020 10:57 AM
You will have to create business rule on sys_user_grmember table to send notifications.
you will have to use GlideAgreegate API methods to count user addition, deletion and then create event to send notifications.
https://developer.servicenow.com/blog.do?p=/post/glideaggregate/
Regards,
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2020 10:59 AM
This is an interesting challenge. I'm thinking of an approach where you have a business rule run after insert. The BR script will check sys_user_grmember for records with that same group, and return the created date/time stamp. If the most recent created date/time is within 10 seconds or whatever fits how you are adding users (a data import or edit in a related list so they all effectively get added at once, or some other way that causes 4 users to be added x seconds apart...) do nothing, otherwise trigger an event. Then you just change your notification to send when the event is triggered.
Deletion is a bit trickier as is doesn't inactivate the group/user relationship, it actually deletes the record, so I'd have to give that a think - not sure if there's an easier way to only send a notification if one hasn't sent in the past x seconds, or maybe there's a way to prohibit an entry in the event queue if it exists in the past x seconds.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2020 02:53 AM
Thanks
Can you please provide a better way to trigger notification once when removing members from the group.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2020 05:26 AM
Create a business rule to trigger an event upon deletion from sys_user_grmember. Include the group name as parm1. Delete a group member so that you can see what that event looks like in the sysevent table. Then create another business rule before insert on sysevent that queries the table for the same Name and Parm1. That combination, along with the created date/time should tell you there were multiple deletions on the same group, versus a deletion in 2 different groups. Then the script will include a line to do not allow the insert if there's a matching record within the past x seconds.
current.setAbortAction(true);