Article [2] -> Automating Weekly Group Incident Summaries Using Flow Designer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
16m ago - last edited 7m ago
Hi all,
Inspired by Aniket Chavan’s Article (brilliant use case, by the way), I decided to approach the problem for group entirely using Flow Designer. In this article, I walk through the complete step-by-step implementation.
Use-Case: Every Monday morning, each assignment group should receive one consolidated email containing all incidents assigned to their group. Additionally, all users belonging to that group must be added to CC. Built purely using just Flow Designer steps
Configure the trigger: Start by defining when the flow should run. Since the requirement is to send daily summary emails, configure a Daily Trigger:
Trigger Type: Weekly
- Day Of Week: Monday
Time: 05:00:00 (any preferred time)
This ensures the flow executes automatically every morning and sends the latest incident summary to each assignment group.
Action Step 1 : Lookup Records on the sys_user_group table with a scripted filter to find only groups who have assigned incidents. I used Flow Designer’s Advanced Condition script option
Here is the script for advanced condition for above step:
/*
** Return all unique assignment groups that currently have incidents
** Output must be an encoded query for sys_user_group
*/
var agg = new GlideAggregate('incident');
agg.addAggregate('COUNT'); // Needed for GA to run
agg.addNotNullQuery('assignment_group'); // Only incidents with a group
agg.groupBy('assignment_group'); // Group by assignment group
agg.query();
var groupIds = [];
while (agg.next()) {
var gid = agg.getValue('assignment_group');
if (gid) {
groupIds.push(gid);
}
}
// Build encoded query for sys_user_group
if (groupIds.length > 0) {
return 'sys_idIN' + groupIds.join(',');
} else {
return 'sys_idINnone'; // Safely return no results
}
Action Step 2: Iterates through the lookup results from Action Step 1.
Action Step 3 : After iteration using lookup record on sys_user_grmember to find users of each group
Action 4: Iterates through the lookup results from Action Step 3.
Action 5: Set flow variable with mail of each user of group
Here is script for flow variable:
var emails = fd_data.flow_var.variable || [];
emails.push(fd_data._4__for_each.item.user.email);
return emails;
Action Step 6: Select the Send Email action.
Set To = group email (dot-walk from Action Step 2).
Set CC = the flow variable from Action Step 5 (convert it to a string as shown below)
Continue: Action Step 6 : For Body of email toggle write script as below
you can tweak this as per your use case
var groupName = fd_data._2__for_each.item.name // data pill: Group name
var groupSysId = fd_data._2__for_each.item.sys_id; // data pill: Group sys_id
var incGr = new GlideRecord('incident');
incGr.addQuery('assignment_group', groupSysId);
// incGr.addQuery('state', '!=', 7); // Skip closed (optional)
incGr.query();
var count = 0;
var message = "<p>Hi " + groupName + " Team,</p>";
message += "<p>This is your <strong>weekly incident summary report</strong> from ServiceNow.</p>";
if (!incGr.hasNext()) {
message += "<p><em>Your group does not have any open incidents at this time.</em></p>";
} else {
message += "<table border='1' cellpadding='4' cellspacing='0' style='border-collapse:collapse; width:100%;'>";
message += "<tr>" +
"<th>#</th>" +
"<th>Incident Number</th>" +
"<th>Short Description</th>" +
"<th>State</th>" +
"<th>Created On</th>" +
"</tr>";
while (incGr.next()) {
count++;
// Truncate long description
var desc = incGr.getDisplayValue('short_description') || "";
if (desc.length > 70) {
desc = desc.substring(0, 70) + "...";
}
message += "<tr>";
message += "<td>" + count + "</td>";
message += "<td>" + incGr.getDisplayValue('number') + "</td>";
message += "<td>" + desc + "</td>";
message += "<td>" + incGr.getDisplayValue('state') + "</td>";
message += "<td>" + incGr.getDisplayValue('sys_created_on') + "</td>";
message += "</tr>";
}
message += "</table>";
}
message += "<br><p>Regards,<br><strong>ServiceNow Notification System</strong></p>";
return message;
Email sent to Group email and users are copied as shown below
Email Preview:
Cross check on incident table list, it matches
Note:
