- 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 08:36 PM
Hello Shaik,
You can use a Schedule here.
Create a new file of Schedule type, add holidays as schedule entries.
When it is done, you can query the global Schedule table, where "name" is your schedule name. Then, if a given day is within the schedule (checked by .isInSchedule call on GlideSchedule object), it is a holiday and you need to choose a different day.
I hope it helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2020 09:10 PM
Hi
Thank you for the reply. I already have the OOB 8-5 weekdays schedule which i need to use can you please help me with the code to apply this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2020 08:36 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2020 09:11 PM
Hi tony,
I do have few more things to do with those ticket update the work notes etc thats why i am going with scheudle job