Aniket Chavan
Tera Sage
Tera Sage

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:

  1. One email per user (not one email per ticket).

  2. Only users with assigned tickets should receive the notification.

  3. 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.

Thinking Math GIF.gif


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.

 

AniketChavan_0-1754920264297.png

 

 

AniketChavan_1-1754920313871.png

 

 


Step 2 – Loop Through Users

Step 2: For Each → Iterates through the lookup results from Step 1.

 

AniketChavan_2-1754920374677.png


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);


AniketChavan_3-1754920428068.png

 

AniketChavan_4-1754920478554.png

 

AniketChavan_5-1754920524525.png

 

 

AniketChavan_6-1754920557868.png

 


Final Output – From an Email Perspective

 

AniketChavan_7-1754920608204.png

 

Walter White Win GIF by Breaking Bad.gif


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:

  1. Lookup relevant users

  2. Loop through them

  3. 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.

 

Reaction Thank You GIF.gif

Comments
Shruti D
Tera Guru

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 

 

 

Aniket Chavan
Tera Sage
Tera Sage

Thanks a lot, @Shruti D! Glad you found it clear and useful 😊

Version history
Last update:
4 weeks ago
Updated by:
Contributors