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-21-2023 04:48 AM
@Priyansh_98Use below script. Also remove setLimit(1) when you are putting this script into scheduled job script as you will have multiple incidents.
var grIncident = new GlideRecord('incident');
grIncident.addEncodedQuery('state=1');
grIncident.setLimit(1);
grIncident.query();
while (grIncident.next())
{
var ticket_updated_time= new GlideDateTime(grIncident.sys_updated_on);
var today = new GlideDateTime();
var duration_seconds = gs.dateDiff(ticket_updated_time, today, true);
var duration_days = Math.round(duration_seconds/ (86400));
gs.info(duration_days);
}
If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2023 05:18 AM
Hi @SANDEEP28 ,
thanks for your response, it is working fine for an incident table.. but when i am using a custom table for the same requirement. the duration time is different. below are the details...
script :
*** Script: number : GBS0035688
*** Script: today : 2023-07-21 12:13:45
*** Script: ticket_updated_time : 2023-04-21 03:19:24
*** Script: duration_seconds : 7894461
*** Script: duration_days : 91
*** Script: number : GBS0039893
*** Script: today : 2023-07-21 12:13:45
*** Script: ticket_updated_time : 2023-04-20 18:32:05
*** Script: duration_seconds : 7926100
*** Script: duration_days : 92
*** Script: number : GBS0039685
*** Script: today : 2023-07-21 12:13:45
*** Script: ticket_updated_time : 2023-04-21 03:29:31
*** Script: duration_seconds : 7893854
*** Script: duration_days : 91
*** Script: number : GBS0035649
*** Script: today : 2023-07-21 12:13:45
*** Script: ticket_updated_time : 2023-04-21 03:12:31
*** Script: duration_seconds : 7894874
*** Script: duration_days : 91
*** Script: number : GBS0040257
*** Script: today : 2023-07-21 12:13:45
*** Script: ticket_updated_time : 2023-04-21 16:31:31
*** Script: duration_seconds : 7846934
*** Script: duration_days : 91
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2023 05:41 AM
@Priyansh_98 What is issue here ? could you please elaborate.
Math.round will round your output. Like if output is 2.95 then it will round up to 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2023 07:52 AM
Hi @SANDEEP28 ,
please check the output, in that you will see the difference between today's date and ticket_updated_time, even if the difference is just a 1 day still it is showing duration days = 91.
that i want to fix.