- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2020 08:11 PM
Hi,
we have a requirement where users who not updated incident assigned to them past 5 business days i want to send a notification to the assigned to & assingned to manager
For that i think i need to write a Scheudule job but can anyone please help me with the code to exclude the holidays & weekends ?
Below is the script which is working for 5 days but not for bsuiness days
var gr = new GlideRecord('incident');
gr.addEncodedQuery('active=true^sys_updated_onRELATIVELE@dayofweek@ago@3');
gr.query();
while(gr.next())
{
gs.eventQueue('my.event', current, gr.assigned_to, gr.assigned_to.manager);
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2020 09:58 PM
Hi Shaik,
try this script below; you will have to iterate over all incident records
that could be a limitation
var incident = new GlideRecord('incident');
incident.addActiveQuery();
incident.query();
while(incident.next()){
var updatedTime = incident.sys_updated_on;
var days = 5;
var dur = new GlideDuration(60*60*24*days*1000);
// paste the sys_id of the 8*5 weekday schedule excluding holidays and weekends
var schedule = new GlideSchedule('090eecae0a0a0b260077e1dfa71da828');
var finalTime = schedule.add(updatedTime, dur,'');
var updatedGdt = new GlideDateTime(updatedTime);
var finalTimeGdt = new GlideDateTime(finalTime);
// if the date/time after adding 5 business days is greater than updated time
if(finalTimeGdt > updatedGdt){
gs.eventQueue('my.event', current, gr.assigned_to, gr.assigned_to.manager);
}
}
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2020 09:18 PM
Hi Shaik,
you can use schedule calculation
1) get the last updated time stamp
2) add 5 business days to it and get that date/time
3) get the current timestamp when job run
4) if current date/time is more than date/time from step 2 it means 5 business days have crossed
do whatever is required
https://community.servicenow.com/community?id=community_blog&sys_id=314e26addbd0dbc01dcaf3231f961986
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2020 09:49 PM
Hi Ankur,
Can you please where do we have schedule calculation ?
Currently i have written a scheduled job as shown in the thread
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2020 09:58 PM
Hi Shaik,
try this script below; you will have to iterate over all incident records
that could be a limitation
var incident = new GlideRecord('incident');
incident.addActiveQuery();
incident.query();
while(incident.next()){
var updatedTime = incident.sys_updated_on;
var days = 5;
var dur = new GlideDuration(60*60*24*days*1000);
// paste the sys_id of the 8*5 weekday schedule excluding holidays and weekends
var schedule = new GlideSchedule('090eecae0a0a0b260077e1dfa71da828');
var finalTime = schedule.add(updatedTime, dur,'');
var updatedGdt = new GlideDateTime(updatedTime);
var finalTimeGdt = new GlideDateTime(finalTime);
// if the date/time after adding 5 business days is greater than updated time
if(finalTimeGdt > updatedGdt){
gs.eventQueue('my.event', current, gr.assigned_to, gr.assigned_to.manager);
}
}
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2020 10:41 PM
One question it means it sends an email for the tickets which are not updated on or before 5 business days.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2020 11:11 PM
Hi Shaik,
it checks those incidents which were updated 5 business days ago.
this is what is required right? any incident which has not been updated in last 5 business day
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader