Email notification for Incident created yesterday (Notification needs to be sent at 05:00 AM PST)

Manthan
Tera Contributor

Hello,

I have a requirement to create a notification for Incidents created on yesterday and the notification needs to be sent at 05:00 AM PST.

I have tried Scheduled Job, Inactivity Monitor and Workflow but neither of them has worked the way I want.

Can anyone please suggest how can I proceed with this?

Also, Please include a script if I need to use a script to achieve this.

Thanks,
Manthan

1 ACCEPTED SOLUTION

Mike Derhammer
Kilo Sage

Hello Manthan,

I've personally used the scheduled job approach in the past, however my solution also utilizes an event and notification. Your scheduled job would be configured to run daily at 05:00 AM PST and would contain a script that runs a GlideRecord query to identify the records you want included. If records are returned in your query, you would then trigger the event, therefore causing the notification to be sent.

You'll need to create the event, the scheduled job, and then the notification.

 

Event Registration Example
Docs - https://docs.servicenow.com/bundle/rome-platform-administration/page/administer/platform-events/task/t_CreateYourOwnEvent.html 

Event Name: incident_followup

Table: Incident

Fired by: Scheduled Job

Description: Triggers the "Incidents Created Yesterday" notification


Scheduled Job - Script Example:

*Interceptor - automatically run a script of your choosing

//Check for Incidents created yesterday and execute an event call

var incRecs = new GlideRecord('incident');
var incArray = []; //An array to hold the information you want included in the email notification
incRecs.addEncodedQuery('sys_created_onONYesterday@javascript:gs.beginningOfYesterday()@javascript:gs.endOfYesterday()');
incRecs.query();

while (incRecs.next()){
incArray.push('Incident Number: ' + incRecs.number.toString() + ',\n');
incArray.push('Incident Short Description: ' + incRecs.short_description + '\n\n');
}

var formattedArray = incArray.join('');
if (incArray) {
    gs.eventQueue('incident_followup',incRecs,formattedArray);
}


Notification - Example:

When to send -

Name: Incident Followup

Table: Incident

Send When: Event is fired

Event name: incident_followup

 

What it will contain -

${event.parm1}

find_real_file.png

Since the array is being passed through the event as parm1 (${event.parm1}), we can use the parameter to insert the data into the notification. In the scheduled job, you can push as many values from the queried incidents as you need.

If this has been helpful and allowed you to achieve what you were looking for, I'd love it if you'd mark it as correct/helpful! If you have additional questions, let me know.

Thank you!

 

View solution in original post

3 REPLIES 3

Mike Derhammer
Kilo Sage

Hello Manthan,

I've personally used the scheduled job approach in the past, however my solution also utilizes an event and notification. Your scheduled job would be configured to run daily at 05:00 AM PST and would contain a script that runs a GlideRecord query to identify the records you want included. If records are returned in your query, you would then trigger the event, therefore causing the notification to be sent.

You'll need to create the event, the scheduled job, and then the notification.

 

Event Registration Example
Docs - https://docs.servicenow.com/bundle/rome-platform-administration/page/administer/platform-events/task/t_CreateYourOwnEvent.html 

Event Name: incident_followup

Table: Incident

Fired by: Scheduled Job

Description: Triggers the "Incidents Created Yesterday" notification


Scheduled Job - Script Example:

*Interceptor - automatically run a script of your choosing

//Check for Incidents created yesterday and execute an event call

var incRecs = new GlideRecord('incident');
var incArray = []; //An array to hold the information you want included in the email notification
incRecs.addEncodedQuery('sys_created_onONYesterday@javascript:gs.beginningOfYesterday()@javascript:gs.endOfYesterday()');
incRecs.query();

while (incRecs.next()){
incArray.push('Incident Number: ' + incRecs.number.toString() + ',\n');
incArray.push('Incident Short Description: ' + incRecs.short_description + '\n\n');
}

var formattedArray = incArray.join('');
if (incArray) {
    gs.eventQueue('incident_followup',incRecs,formattedArray);
}


Notification - Example:

When to send -

Name: Incident Followup

Table: Incident

Send When: Event is fired

Event name: incident_followup

 

What it will contain -

${event.parm1}

find_real_file.png

Since the array is being passed through the event as parm1 (${event.parm1}), we can use the parameter to insert the data into the notification. In the scheduled job, you can push as many values from the queried incidents as you need.

If this has been helpful and allowed you to achieve what you were looking for, I'd love it if you'd mark it as correct/helpful! If you have additional questions, let me know.

Thank you!

 

Hello Michael,

Thank you so much for your brief response.

I do appreciate you taking the time to respond to my issue.

I have not tried this yet, but I will let you know once I implement this.

Thank you,
Manthan

Hello Michael,

I implemented the same idea and the same script with some tweaks as required by my client and the notification seems to be working perfectly fine.

Script I used for testing is as below:

var gr = new GlideRecord ('incident');
gr.AddEncodedQuery('sys_created_onONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()^sys_domain=1bd02a101bc173003d6843fccd4bcb5f^assigned_toISEMPTY');
gr.query();

while (gr.next()){
	gs.eventQueue('email.alert', gr);
}


I hope your proposed solution helps other people as well.

Thank you, and have a great day ahead!


Manthan