Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Need to send an email with list of incidents which are not updated more than 2 days

VijayramY
Tera Contributor

Need to send an email every day with list of incidents which are not updated more than 2 days. Here trigger condition is , if any incident is not updated more than 2 days
please guide me on how to achieve this.

7 REPLIES 7

Nehal Dhuri
Mega Sage

You need to create a scheduled job for this and trigger the event from scheduled job to send the notification and in event parameter you need to pass a list of incidents in an array or in object so that you can use it in email body

Please hit like and mark my response as correct if that helps

@Nehal Dhuri @VijayramY 

yes, exactly - a scheduled job or a flow.

 

Optimally use event and that would be a notification trigger, or you can send that notification from flow as well.

 

buuuuut be careful not to trigger each incident separately 😄 and also, these scheduled reports are usually executed early morning or late nights.

 

If you want to have in last 2 days, be careful not to send on Monday with no update during the weekend so exclude that...

———
/* If my response wasn’t a total disaster ↙️ drop a Kudos or Accept as Solution ↘️ Cheers! */


Ankur Bawiskar
Tera Patron
Tera Patron

@VijayramY 

email has to be sent to whom? Assigned to -> Manager with list of all INCs not updated by his/her Assignee in last 2 days?

what's your exact business requirement?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Rafael Batistot
Kilo Patron

Hi @VijayramY 

You need create:

1 - Event (To triger the notification)
2 - Notification (Event is fired with your event) 
3 - Mail scrip (with information that you need "list of incidents which are not updated more than 2 days"
4 - Schedule job (Run daily) 

See some code exemples: 

Schedule job: 

(function() {
    var gr = new GlideRecord('incident');
    gr.addEncodedQuery('sys_updated_onRELATIVELE@dayofweek@ago@2'); // not updated in 2+ days
    gr.addActiveQuery(); 
    gr.query();

    if (gr.hasNext()) {
        gs.eventQueue("custom.incident.stale.report", null, "", "");
    }
})();


Mail script: 

// Mail Script: Incident not updated for 2+ days
(function() {
    var gr = new GlideRecord('incident');
    gr.addEncodedQuery('sys_updated_onRELATIVELE@dayofweek@ago@2'); // not updated in 2+ days
    gr.addActiveQuery(); // only active incidents
    gr.query();

    var body = "";
    body += "<p>Hello,</p>";
    body += "<p>Here are incidents not updated for more than 2 days:</p>";
    body += "<table border='1' cellpadding='5' cellspacing='0'>";
    body += "<tr><th>Number</th><th>Short Description</th><th>Assigned To</th><th>Last Updated</th></tr>";

    while (gr.next()) {
        body += "<tr>";
        body += "<td>" + gr.number + "</td>";
        body += "<td>" + gr.short_description + "</td>";
        body += "<td>" + gr.assigned_to.getDisplayValue() + "</td>";
        body += "<td>" + gr.sys_updated_on.getDisplayValue() + "</td>";
        body += "</tr>";
    }

    body += "</table>";
    body += "<br/><p>Regards,<br/>ServiceNow</p>";

    template.print(body);
})();

 

Step 3: Create a Notification

  1. Go to System Notification → Email → Notifications.
  2. Create a new notification:
    • When to send: Event is fired.
    • Event name: custom.incident.stale.report.
    • Who will receive: desired group, distribution list, or email addresses.
    • What it will contain: add a Mail Script.



If you found this response helpful, please mark it as Helpful. If it fully answered your question, consider marking it as Correct. Doing so helps other users find accurate and useful information more easily.