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 11:30 AM
@Priyansh_98 From your output, I can see ticket update time 21st April, thats why difference is coming as 91 days 🙂 Please check month
ticket_updated_time : 2023-04-21 03:19:24 --> this 21 April 2023
Today's date : 2023-07-21 12:13:45 ---> 21st July 2023
If I could help you with your Query then, please hit the Thumb Icon and mark as Correct the solution which I gave in previous post so that it will help others.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2023 05:11 AM - edited ‎07-21-2023 05:19 AM
Hello @Priyansh_98
This can be achieved via flow designer. That would be more easy.
or
Please update your script like this, I hope this will resolve your issue
var gr = new GlideRecord('incident');
gr.addQuery('state', '3');
//gr.setLimit(1);
gr.query();
while (gr.next()) {
var updated = gr.sys_updated_on;
var ticket_updated = new GlideDateTime(updated);
var today = new GlideDate();
var duration_seconds = gs.dateDiff(today, ticket_updated, true);
var duration_days = Math.round(duration_seconds / (86400)); // Divide by the number of seconds in a day (86400)
gs.print(updated);
gs.print('today: ' + today);
gs.print('seconds: ' + duration_seconds);
gs.print('days: ' + duration_days);
}
Please mark my answer Helpful &Accepted solution if you find the useful
Thanks,
Praneeth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2023 05:31 AM
Hi @praneeth7 ,
thanks for your response...
can you please look into the comments which I have added above?
the issue is still there...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2023 06:15 AM
Hello @Priyansh_98
Please try this code,
var grIncident = new GlideRecord('x_aai_gbs_finanapp_gbs_finance');
grIncident.addEncodedQuery('state=19');
grIncident.setLimit(5);
grIncident.query();
while (grIncident.next()) {
var ticket_updated_time = new GlideDateTime(grIncident.sys_updated_on);
var today = new GlideDateTime();
today.setHourOfDay(0);
today.setMinute(0);
today.setSecond(0);
today.setMillisecond(0);
var duration_seconds = gs.dateDiff(ticket_updated_time, today, true);
var duration_days = Math.round(duration_seconds / (86400));
gs.print('duration_days: ' + duration_days);
}
Thank you,
Praneeth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-25-2023 03:10 AM
hi @praneeth7 ,
how can I configure it b flow can you please explore a little bit more?
like what should be the trigger condition and what should be the action flow?