How to get one email notification if user is inactive
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2023 04:15 AM
Hi Everyone,
I have a requirement
Need To Identify When User Marked As Inactive Is Also Assigned As A Group Manager.
I have created one BR on Sys_user table triggering Notification currently.
var gr = new GlideRecord('sys_user_group');
gr.addEncodedQuery('active=true^manager.active=false');
gr.query();
while (gr.next()) {
gs.eventQueue("user.inactive.group.manager", gr);
}
Here the issue is If one is user is manager for Multiple groups it triggering notification for each group one notification.
I need to send only one notification If the user is manager for multiple groups and also need to Update all the groups name in notification body.
Thanks,
Prasad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2023 04:19 AM
check this link where I shared solution for something similar. enhance it for your requirement
How to trigger multiple notifications for multiple users ?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2023 04:25 AM
Hi @Ankur Bawiskar ,
Thanks for reply,
In my case, I'm triggering notification only the user is manger of any one of the group. Here i'm facing issue is- If the user is manager for multiple groups my notification is triggering mulitple times. So i need to send this notificaion only once and also need to populate the all the group names which the user is manager in notification Body.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2023 05:15 AM
the link I shared has logic for something similar requirement.
Did you check that?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2023 06:00 AM
Hi Ankur,
I have checked the logic and tried to use same kind logic in my case it is not returning all the group names only printinng one group name that also not relevent.
Here my script:
BR
(function executeRule(current, previous /*null when async*/ ) {
var groupNames = [];
var gr = new GlideRecord('sys_user_group');
gr.addEncodedQuery('active=true^manager.active=false');
// gr.setLimit(1);
gr.query();
while (gr.next()) {
groupNames.push(gr.name.toString());
gs.eventQueue("user.inactive.group.manager", current, gr.name);
}
})(current, previous);
Email script:
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
var gr = new GlideRecord("sys_user_group");
gr.addQuery('name', event.parm1);
gr.query();
while (gr.next()) {
template.print(gr.name);
template.print("<br/>");
}
Could you help me to correct the script.
Thanks,
Prasad