- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2022 01:51 AM
Hi Team,
I have a schedule job which is removing the users from groups and removing the roles.
But I want to send a notification to a particular group with the User Name and Group details from which they are removed.
I am struck with how to trigger an event and send notification.
Here is my script:
var roles=new GlideRecord('sys_user_has_role'); // go to user role table
roles.addEncodedQuery('role!=2831a114c611228501d4ea6c309d626d^user.last_login_time<javascript:gs.beginningOfLast3Months()');
roles.query();
while(roles.next())
{
var SID=roles.user;
var userMem=new GlideRecord('sys_user_grmember');
userMem.addQuery('sys_id',SID);
userMem.query();
var removedFromGroups = [];
if (userMem.next()) {
userMem.deleteRecord();
removedFromGroups.push(userMem.group.getDisplayValue());
}
gs.print(userMem.user + " " + removedFromGroups);
gs.eventQueue('notification_to_group', current,);
}
roles.deleteMultiple();
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2022 08:35 PM
@KARAN
Hi,
event, notification on gr member table correct
trigger the event from before delete BR
gs.eventQueue('event_name', current, 'recipient', current.user.name + '@' + current.group.name);
Now you are sending the user and group in event parm2
in email script you can split it with @ and then print the user and group
var user = event.parm2.split('@')[0];
var group = event.parm2.split('@')[1];
I believe I have provided enough help for your question.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2022 02:49 AM
Hi,
send the email notification via Before delete BR on sys_user_grmember table and not via scheduled job
Reason being by the time the event is processed the record may not exist as it is deleted
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2022 02:54 AM
Hi Ankur,
Can we just send the list of users for whom the group is deleted.Not the group details
Thanks,
Karan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2022 03:52 AM
Hi,
yes why not your notification is on Group member table you can include that detail of user and group in email body
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2022 04:12 AM
Hi Ankur,
So,I need to create an event on Group member table and even the notification right.
Then can you please help me the code of calling the event so that when it called in notification,the details of the users who are removed are sent to one particular group.
Thanks,
Karan