Notification should trigger for aging incidents

Avee90
Tera Contributor

Hello Folks,
Notifications should trigger to assigned user for open incidents if the incident reaches to 30th day, 60th day and 90th from the creation of incident. Can someone help to achieve this. I'm new to scripting.

7 REPLIES 7

Fixing the Script to Use Incident Number

If you're sending a notification or logging something and want the incident number instead of the sys_id, update your script like this:

 

(function() {
var gr = new GlideRecord('incident');
gr.addQuery('state', '!=', '7'); // Not Closed
gr.query();

while (gr.next()) {
var createdDate = new GlideDateTime(gr.sys_created_on);
var now = new GlideDateTime();
var diffDays = GlideDateTime.subtract(now, createdDate).getNumericValue() / (1000 * 60 * 60 * 24);

if (diffDays == 30 || diffDays == 60 || diffDays == 90) {
var incidentNumber = gr.number.toString(); // Get the incident number
var assignedTo = gr.assigned_to.getDisplayValue(); // Get the display name of the user

// Optionally log or use these values
gs.info("Notifying " + assignedTo + " about incident " + incidentNumber);

// Trigger event with useful info
gs.eventQueue('incident.age.notification', gr, assignedTo, incidentNumber);
}
}
})();

 

 

  • gr.number.toString() → gets the human-readable incident number like INC0012345

  • gr.assigned_to.getDisplayValue() → gets the user's name instead of their sys_id

  • You can pass these values into your event or notification template for clarity

 

Actually, at second glance, it's not the sys_id, it says fd_transform:<string of random numbers>.

 

nickde
Tera Contributor

Actually, I got it working. For some reason, the For each Incident record took FOREVER to load the referenced fields.  I guess I need to be patient...