Need to send notifications for selected incidents group by assignment group
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2024 08:40 AM
Hi,
Need to send notifications for incidents that are filtered based on some criteria. The catch is that if we group these incidents by their assignment group then there should be 1 notification per assignment group and that notification should include the count of incidents (with that particular assignment group).
How can we achieve this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2024 10:08 AM
Hi @rahul gupta6 ,
GlideRecord the Incident table with your filtered criteria. Now, get all the Unique assignment groups with Incidents associated to it. Create a Event queue and sent the group and count as parameters in the notifications in an On demand scheduled job or scripts - background itself.
Check the below code:
var grINC = new GlideRecord('incident');
//Add your own query
grINC.query(); // Run the query
var groupCounts = {}; // Object to store the assignment groups and their counts
while (grINC.next()) {
var groupName = grINC.getDisplayValue('assignment_group');
//var groupName = grINC.getValue('assignment_group');
// If the group is already in the groupCounts object, increment the count
if (groupCounts[groupName]) {
groupCounts[groupName]++;
} else {
// Otherwise, initialize the count for this group to 1
groupCounts[groupName] = 1;
}
}
// Log the unique assignment groups and their incident counts
for (var name in groupCounts) {
gs.info('Assignment Group: ' + name + ' has ' + groupCounts[name] + ' incidents');
//gs.eventQueue(event_name, current, name, groupCounts[name]);
}
// Add your own query ---- the filter that you need at the start and try the above script in the scripts - background and check the output.
Make sure to comment out,
var groupName = grINC.getDisplayValue('assignment_group'); when running in the on demand scheduled job,
and uncomment the below line
// var groupName = grINC.getValue('assignment_group'); ----- It will give the sys_id. So use this which will be used in the notification.
// gs.eventQueue(event_name, grINC, name, groupCounts[name]);
---- event_name is the name of the event, grINC is the object used, name is the sys_id of the record, groupCounts[name] will be the number.
Uncomment it, when running in the scheduled job.
In the notification, Who will receive, checkbox the field "Event parm 1 contains recipient", which represents the Assignment group first parameter.
Use ${event.parm2} in the What it will contain of the notification to get the count of the Incidents, which represents the second parameter.
IF the above information helps you, Kindly mark it as HELPFUL and Accept the solution.
Regards,
Najmuddin.