- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2025 02:20 AM
Hi Everyone,
I have a requirement to implement an action for each active group record. After processing each group, I need to check if the group has an active manager. If an active manager exists, a notification should be triggered via the "Fire Event" in FD.
However, I want to avoid triggering the notification multiple times when a manager has multiple assigned groups. Since the system iterates over each group and the notification is triggered each time a group with an active manager is found, the notification may be fired multiple times for the same manager because it has assign multiple group.
The goal is to restrict the "Fire Event" to trigger only once per manager, even if they are assigned to multiple groups.
I have implemented the FD as shown in the screenshot below. Could you please review it and suggest any changes or improvements to achieve this functionality?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2025 10:40 PM
Hope you are doing good.
Did my reply answer your question?
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
04-09-2025 02:29 AM
Hello @rmaroti
You can use below 👇 script to get aall active groups unique managers in an array. And then run for each to send mail once to all. Since it's unique manager array that its returning no double mail.
You can modify the condition as per your requirement -
var uniqueManagers = {};
var mgrNames = {};
var gr = new GlideRecord('sys_user_group');
gr.addQuery('active', true);
gr.query();
while (gr.next()) {
var manager = gr.getValue('manager');
if (manager && !uniqueManagers[manager]) {
uniqueManagers[manager] = true;
var user = new GlideRecord('sys_user');
if (user.get(manager)) {
mgrNames[manager] = user.getDisplayValue();
}
}
}
for (var id in mgrNames) {
gs.info('Manager: ' + mgrNames[id] + ' | sys_id: ' + id);
}
Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket.
Regards,
Shivalika
My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194
My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2025 02:51 AM
not possible using flow designer.
Please use daily scheduled job or frequency as per your customer requirement
something like this but please enhance
I hope you know how to create event, notification linked to that event and you can enhance it further
(function executeJob() {
// Create a map to group active groups by their manager
var managerGroupMap = {};
// Query all active groups
var groupGr = new GlideRecord('sys_user_group');
groupGr.addQuery('active', true); // Only active groups
groupGr.query();
while (groupGr.next()) {
var managerSysId = groupGr.manager.toString(); // Get the manager's sys_id
var groupName = groupGr.getDisplayValue('name'); // Get the group's name
if (!managerSysId) {
continue; // Skip groups without managers
}
// Add group names to the manager's list in the map
if (!managerGroupMap[managerSysId]) {
managerGroupMap[managerSysId] = [];
}
managerGroupMap[managerSysId].push(groupName);
}
// Iterate through the map and send one email per manager
for (var managerSysId in managerGroupMap) {
var groupList = managerGroupMap[managerSysId].join("\n"); // Create a list of groups
// Get the manager's record
var managerGr = new GlideRecord('sys_user');
if (managerGr.get(managerSysId)) {
var emailAddress = managerGr.email;
if (emailAddress) {
// Fire an event to send the email notification
gs.eventQueue('send_manager_email', null, emailAddress, groupList);
gs.info("Email triggered for Manager: " + emailAddress + " with Groups:\n" + groupList);
} else {
gs.warn("Manager does not have an email address: " + managerSysId);
}
}
}
})();
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
04-10-2025 04:46 AM
Hope you are doing good.
Did my reply answer your question?
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
06-15-2025 10:40 PM
Hope you are doing good.
Did my reply answer your question?
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