notification after 3 days in servicenow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2023 03:58 AM
I have to send a notification to the user when the ticket is 3 days old and the state is in awaiting info state and when a ticket is in the "awaiting info" state for more than 6 days, then the ticket should be canceled.. i have created scheduled jobs and added this script...
the problem is I am not able to get the days count even though the ticket is updated recently also it does not show the correct days count.
i am using an updated date field for taking the difference between today's date and updated date for trigeering the condition.
script :
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2023 04:11 AM
Hello @Priyansh_98
I did not test it, but you can configure something like this,
I have used send email action here, if you want send some notification also you can replace it with your notification.
If you find this useful Please mark my answer Helpful & Accepted Solution
Thank you

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2023 03:30 AM
Hi the below is the schedule job which will close after 10 days when there is no repsonse, modify this as per your requirement
checkINC();
function checkINC() {
// This INC job will check all non updated incidents for last 10 days and closes the incident. A OOB closed notification will be sent by comments
//Incase Incident get any comments/worknotes. The timer will reset.
var updatedDate = '';
var today = new GlideDateTime();
var today_date = today.getDate();
var gr = new GlideRecord('incident');
gr.addActiveQuery();
gr.addQuery('state', '4');
gr.query();
while (gr.next()) {
updatedDate = new GlideDateTime(gr.getValue('sys_updated_on'));
updatedDate = updatedDate.getDate();
var dur = GlideDateTime.subtract(updatedDate, today_date).getRoundedDayPart();
if (dur == '10') {
gr.close_code = 'No Response'; // Unknown
gr.close_notes = "Incident Closed due to no response from Caller.";
gr.u_cause = "Knowledge/Training Related";
gr.state = 7; //closed
gr.active = false;
gr.comments = 'Incident automatically closed after ' + 10 + ' days in a Awaiting User Information status';
// gs.eventQueue("inc.reminder", inc, inc.caller_id, gs.getUserName());
gr.update();
}
}
}
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2023 04:33 AM
Hi @Priyansh_98 ,
Hope you are doing great.
Please try using below script :
var gr = new GlideRecord('incident');
gr.addQuery('state', 'awaiting info');
gr.addQuery('sys_updated_on', '<', gs.daysAgo(3));
gr.query();
while (gr.next()) {
var updated = gr.sys_updated_on;
var ticket_updated = new GlideDateTime(gr.sys_updated_on);
var today = new GlideDateTime();
var duration_seconds = gs.dateDiff(ticket_updated, today, true);
gs.print('Ticket Number: ' + gr.number);
gs.print('Updated Date: ' + updated);
gs.print('Today: ' + today);
gs.print('Seconds since last update: ' + duration_seconds);
if (duration_seconds > (6 * 24 * 60 * 60)) {
// Cancel the ticket as it has been in "awaiting info" state for more than 6 days
gr.state = 4; // Assuming 4 is the code for "canceled" state
gr.update();
gs.print('Ticket has been canceled.');
} else if (duration_seconds > (3 * 24 * 60 * 60)) {
// Send notification as the ticket is 3 days old and still in "awaiting info" state
gs.print('Sending notification to user.');
// Add your notification logic here.
}
}
Regards,
Riya Verma