top of page

Experiencing challenges with ServiceNow support?

Access professional, reliable assistance tailored to your needs—without breaking your budget.

Beyond the Basics: Leveraging ServiceNow Email Notifications for Custom Reports

Updated: Mar 28

ServiceNow offers a robust reporting engine, empowering users to easily visualize and analyze platform data. However, there are scenarios where the standard reporting tools might not fully address specific needs, particularly when dealing with intricate queries involving multiple tables or complex date-based filtering. This is where a creative and often overlooked solution comes into play: utilizing ServiceNow email notifications to generate custom reports. This article explores this powerful technique, providing a step-by-step guide for ServiceNow users who need more flexibility in their reporting capabilities.


While ServiceNow's built-in reports are excellent for many purposes, situations arise where you might need to go beyond their standard functionalities. Perhaps you want to combine data from several different tables based on specific criteria, or maybe you need to present information in a highly customized format within a scheduled report. In such cases, repurposing email notifications can be an effective alternative for creating custom reports tailored to your exact requirements.


Unlocking the Potential of Email Notifications for Data Delivery

ServiceNow email notifications, primarily designed for alerting users about events, can be transformed into powerful custom reporting tools. The key advantage lies in the complete control you gain over the content and formatting of the output. Leveraging HTML within the email body allows for rich presentations with colors, varied fonts, and structured tables. Furthermore, the integration with ServiceNow scripting enables you to dynamically query and present data from virtually any table within the platform.


Crafting Your Custom Report: A Step-by-Step Approach

Let's walk through the process of setting up a custom report using email notifications, focusing on a common use case: a scheduled report of active incidents.

  1. Define a Custom Event: The first step is to create a custom event within ServiceNow. This event will act as the trigger for your email notification report. To create an event, navigate to "System Policy" > "Events" > "Registry" and click "New". Provide a descriptive name for your event (e.g., incident.aging.report) and specify the table it relates to (in this case, incident).

  2. Schedule the Event Trigger: Next, you need to schedule a script to automatically fire this event at your desired frequency (e.g., daily at 7:00 AM). Navigate to "System Definition" > "Scheduled Jobs" and click "New". Choose "Automatically run a script of your choosing". In the script field, you can add logic to control when the event is raised. For example, to run the report on weekdays, you could use the following script:

    JavaScript

var dayOfWeek = new Date().getDay(); // 0 = Sunday, 6 = Saturday if (dayOfWeek >= 1 && dayOfWeek <= 5) {
	gs.eventQueue("incident.aging.report", null, null, null);
}
  1. Remember to set the "Run" field to "Daily" and configure the appropriate "Time" for execution.

  2. Configure the Email Notification: Now, create or modify an email notification that will be triggered by the event you just created. Navigate to "System Notification" > "Email" > "Notifications" and click "New".

    • Set the "Send when" field to "Event is fired".

    • In the "Event name" field, select the custom event you created (incident.aging.report).

    • You can optionally add conditions to further refine when this notification should be sent, but for this example, we'll focus on the mail script.

    • On the "Who will receive" tab, specify the recipients of this report. For testing, you might want to select "Send to event creator".

  3. Designing the Report Content with Mail Script: The core of this solution lies in the "Message" field on the "What it will contain" tab. Ensure you are using the HTML version of the message. Within this field, you can embed ServiceNow script using the <mail_script> tags. This script will execute when the notification is triggered, allowing you to query data and format it for your report. Here's an example of a mail script to generate a report of active incidents created within different age ranges:

    HTML

<p>The following active Incidents were created at least 7 days ago:</p>
<mail_script>
    var baseUrl = gs.getProperty("glide.servlet.uri");

    // Query for incidents created 7 to 13 days ago
    var grRecent = new GlideRecord("incident");
    var recentQuery = "active=true^sys_created_onBETWEEN" + 
                      "javascript:gs.daysAgoEnd(13)@" + 
                      "javascript:gs.daysAgoStart(7)";
    grRecent.addEncodedQuery(recentQuery);
    grRecent.orderBy('sys_created_on');
    grRecent.query();

    if (grRecent.hasNext()) {
        template.print("<h3>Incidents Created Within 7 - 13 Days:</h3>");
        while (grRecent.next()) {
            template.print(grRecent.getDisplayValue('sys_created_on') + 
            " - <a href='" + baseUrl + grRecent.getLink() + "'>" + 
            grRecent.getValue('number') + "</a> - " + 
            grRecent.short_description + "<br/>");
        }
    }

    // Query for incidents created 14 to 29 days ago
    var grOlder = new GlideRecord("incident");
    var olderQuery = "active=true^sys_created_onBETWEEN" + 
                     "javascript:gs.daysAgoEnd(29)@" + 
                     "javascript:gs.daysAgoStart(14)";
    grOlder.addEncodedQuery(olderQuery);
    grOlder.orderBy('sys_created_on');
    grOlder.query();

    if (grOlder.hasNext()) {
        template.print("<h3>Incidents Created Within 14 - 29 Days:</h3>");
        while (grOlder.next()) {
            template.print(grOlder.getDisplayValue('sys_created_on') + 
            " - <a href='" + baseUrl + grOlder.getLink() + "'>" + 
            grOlder.getValue('number') + "</a> - " + 
            grOlder.short_description + "<br/>");
        }
    }
</mail_script>

This script demonstrates how to query the incident table for active records created within specific date ranges using addEncodedQuery. The results are then formatted using template.print() to display the creation date, incident number (as a clickable link back to the record), and the short description. You can expand this script to include more queries, different tables, and more sophisticated HTML formatting to create visually appealing and informative reports directly within the email body.


Practical Applications and Considerations

Using email notifications for custom reports opens up numerous possibilities:

  • Generating reports that require data aggregation or comparisons not easily achievable with standard reports.

  • Creating highly formatted reports tailored to specific audiences or branding guidelines.

  • Delivering scheduled reports with dynamic content based on complex filtering criteria.

However, it's important to consider the following:

  • Maintenance: Managing and updating these custom email-based reports requires familiarity with ServiceNow scripting.

  • Complexity: For very intricate reporting needs, dedicated reporting tools or Performance Analytics might be more suitable.

  • Email Limitations: Very large datasets might lead to excessively long emails, which could be difficult to manage.


Alternative Solutions

While email notifications offer a unique approach, remember that ServiceNow's standard reporting features are continuously being enhanced. Explore the possibilities of creating scheduled reports with advanced filters and potentially combining multiple reports on a dashboard. For more sophisticated analytics and visualizations, consider leveraging ServiceNow's Performance Analytics module.


Conclusion

Leveraging ServiceNow email notifications as custom reports provides a flexible and powerful way to deliver tailored information directly to users. By combining the triggering mechanism of events, the scheduling capabilities of scheduled jobs, and the dynamic data retrieval and formatting offered by mail scripts, you can overcome some of the limitations of standard reporting. While this technique requires some scripting knowledge and careful planning, it can be an invaluable tool in your ServiceNow toolkit for meeting unique reporting requirements. As a next step, consider identifying a reporting need in your organization that isn't easily met by standard reports and explore how this method could provide a custom solution. Remember to test your configurations thoroughly in a non-production environment before deploying them to your live instance.

Experiencing challenges with ServiceNow support?

Access professional, reliable assistance tailored to your needs—without breaking your budget.

CONTACT

New Zealand HQ

Integrated Knowledge Consulting Office

Level 3, 93 Grafton Road

Auckland

South Korea

Integrated Knowledge Consulting Office

BMY역삼타워 6층

서울특별시 강남구 역삼동 678-10번지

 

info@ikconsulting.com

Thanks for submitting!

  • LinkedIn Social Icon

© Copyright 2025 Integrated Knowledge Consulting. All rights reserved.

bottom of page