- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
4 weeks ago
Hello Community,
Recently, I implemented a feature in my project that I thought might be worth sharing. The requirement was straightforward but interesting:
Send each user a weekly summary email containing all their active Incident tickets in a single notification.
While many experts might achieve this in different ways — for example, using Scheduled Jobs and Events — I took an approach entirely in Flow Designer, which made it quick to build, easy to maintain, and quite flexible for future enhancements.
This article walks through the exact steps, scripts, and design choices I used so that if anyone faces a similar requirement in the future, they can replicate it easily.
The Requirement
Every Monday morning, each user should receive one email listing all open or active Incidents assigned to them.
The email should include:
-
Ticket Number
-
Short Description
-
State
-
Created Date
The key points were:
-
One email per user (not one email per ticket).
-
Only users with assigned tickets should receive the notification.
-
Email content should be nicely formatted and personalized.
My First Roadblock
The first challenge was identifying the right set of users.
A simple lookup of all active users and looping through them in Flow Designer wasn’t optimal — it would unnecessarily iterate over the entire sys_user
table, even for users with no assigned tickets.
Instead, I needed a way to:
-
Query the Incident table directly for active assignments.
-
Extract the unique Assigned To users from that result set.
-
Feed only those users into the notification process.
Step 1 – Flow Designer Setup
Trigger: Scheduled trigger set to run every Monday at the desired time.
Step 1: Lookup Records on the sys_user
table with a scripted filter to find only users who have assigned Incidents.
I used Flow Designer’s Advanced Condition script option:
/*
**Access Flow/Action data using the fd_data object. Script must return a value.
*/
// Query incident records with an assigned_to value
var incGr = new GlideRecord('incident');
incGr.addNotNullQuery('assigned_to');
incGr.query();
var userIds = [];
// Collect unique user sys_ids
while (incGr.next()) {
var uid = incGr.getValue('assigned_to');
if (userIds.indexOf(uid) === -1) {
userIds.push(uid);
}
}
// Build encoded query for sys_user table
if (userIds.length > 0) {
return 'sys_idIN' + userIds.join(',');
} else {
return 'sys_idINnone'; // no matching users
}
This ensures that only users with at least one assigned Incident are included.
Step 2 – Loop Through Users
Step 2: For Each → Iterates through the lookup results from Step 1.
Step 3 – Send Notification
Initially, I used Send Notification referencing a pre-built notification in sys_user
.
That notification:
-
Send when: Triggered
-
Recipients: User's email (
email
field) -
Subject:
"Your Weekly Incident Summary Report"
-
Message: Calls an Email Script:
${mail_script:To_get_the_user_summary}
Email Script – To_get_the_user_summary
(function runMailScript(current, template, email, email_action, event) {
var userName = current.getDisplayValue('name');
var userSysId = current.getValue('sys_id');
var incGr = new GlideRecord('incident');
incGr.addQuery('assigned_to', userSysId);
incGr.query();
var count = 0;
var message = "<p>Hi " + userName + ",</p>";
message += "<p>This is your <strong>weekly incident summary report</strong> from ServiceNow.</p>";
if (!incGr.hasNext()) {
message += "<p><em>You did not have any incident assignments during the last week.</em></p>";
} else {
message += "<table border='1' cellpadding='4' cellspacing='0'>";
message += "<tr><th>#</th><th>Incident Number</th><th>Short Description</th><th>State</th><th>Created On</th></tr>";
while (incGr.next()) {
count++;
message += "<tr>";
message += "<td>" + count + "</td>";
message += "<td>" + incGr.getDisplayValue('number') + "</td>";
message += "<td>" + incGr.getDisplayValue('short_description') + "</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>";
template.print(message);
})(current, template, email, email_action, event);
Final Output – From an Email Perspective
Why I Chose This Approach
While I could have used a Scheduled Script Execution (Scheduled Job) combined with an Event and Notification setup to trigger the emails, I found that using Flow Designer made it easier to directly filter the users and send notifications in a single flow.
This approach felt simpler to implement, easier to maintain, and more visual and transparent in execution flow.
Outcome
In just three Flow Designer actions:
-
Lookup relevant users
-
Loop through them
-
Send a personalized summary notification
…the requirement was met with minimal complexity.
The feedback from the client was positive, and I believe this approach could help others looking to send batch summary notifications for any record type — not just Incidents. In fact, I originally implemented this for the Risk Response Task table, as that was the actual client requirement. I simply tested the same setup on the Incident table to validate how it worked.
Conclusion
If you need to send weekly or periodic record summaries in ServiceNow, Flow Designer combined with an Email Script can be a quick, efficient solution.
Hopefully, this walkthrough helps save you time if you encounter a similar request.
- 523 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hello @Aniket Chavan,
Thanks for sharing this article! The steps for setting up the weekly incident summary using Flow Designer are explained really clearly. The step-by-step screenshots make the process much easier to follow. I really appreciate the detailed guidance!
Regards,
Shruti
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Thanks a lot, @Shruti D! Glad you found it clear and useful 😊