Excluding the Weekends in Schedule Job
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2016 09:32 AM
Hi All,
Appreciate your help,
We are designing the Approval Reminder notifications for pending approvals. Which are exceeded the 3 days then we need t send an reminder for the approver and which exceeds the 5 days we are auto rejecting the approval. For this i created two scheduled jobs which will check for three days and five days and successfully triggering the Emails with pending and rejection.
Came up with another work, we need to exclude the weekends from this. So i checked in web and found some solutions like below
var schedule = new GlideSchedule("607e96184fa88200142ad0af0310c7ff"); // sys_id of the schedule which our organisation is using for to calculate the holidays and work time 7am - 5pm
if(schedule.isInSchedule(new GlideDateTime(gs.nowDateTime())))
{ code here......}
/// not able to triggering the emails when i am using the above code
In the condition of the Schedule job i used the below script. ---- This script is triggering the emails and running the schedule job for monday to friday.
var answer = false;
//Get the day of week. 1=Monday, 7=Sunday
var now = new GlideDateTime();
//Run only on weekdays
if(now.getDayOfWeek() != 2){
answer = true;
}
answer;
// the above script is not taking the holidays into account and i am using the below script for the schedule job.
var eQuery = "sys_created_onRELATIVELT@dayofweek@ago@3";
var app = new GlideRecord('sysapproval_approver');
app.addQuery('state','requested');
app.addEncodedQuery(eQuery);
app.orderBy('approver');
app.query();
while(app.next()){
gs.eventQueue('request.approval.reminder', app, app.approver);
}
So my Query is
1 -> How to exclude the weekends and holidays using the Schedule in the schedule job
2-> Currently is we are taking the Sys created record date - for example if an approval is generated on Friday, then saturday and sunday the schedule job will not work and when its works on monday then it will trigger the email to the record which is created on friday. Bcoz its calculating the duration based on the created date. So how to calculate the duration only between monday to friday excluding the weekends. So if i record is opened on friday it has to consider the friday as the day 1 and Monday as day 2 and Tues as day3 then it has to send on the wed the pending email.
Appreciate your help on this!!!!
Thanks
Raghu

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2016 09:39 AM
Hi Raghu,
The GlideSchedule API may be what you are looking for to access schedules/calendars.
Using Schedules - ServiceNow Wiki
Scoped GlideSchedule API Reference - ServiceNow Wiki
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2016 09:59 AM
Hi Ctomasi,
Thanks for the quick response,
I am using the default schedule only - 8-5 working excluding holidays -
When i am using that Schedule in the starting of my script in schedule job - I cannot see any email logs - Emails are not at all triggering when i click the execute action also. As i mentioned on the top when i used the below script in the condition then i can customise it in between the monday - friday only.
var answer = false;
//Get the day of week. 1=Monday, 7=Sunday
var now = new GlideDateTime();
//Run only on weekdays
if(now.getDayOfWeek() != 2){
answer = true;
}
answer;
I tried using the schedule like the below but still no luck.
var schedRec = new GlideRecord('cmn_schedule');
schedRec.get('name', 'M-F,7-5,Excluding Holidays');
var sched = new Packages.com.glide.schedules.Schedule(schedRec.sys_id);
if(sched.isInSchedule(gs.nowDateTime())){ Code here.....
Can u please suggest me how to get rid of the week end days. As i mentioned in the earlier example if an approval is requested on friday and it has t trigger the pending email on wednesday. (actually its 5 days but it has to take out the Sat & sun and then has to calculate the 3 days)
If we use the schedule then it will check only the Hours mentioned in the schedule - Eg: if 7-5 - 10Hrs / day so for 3 days its 24*3 = 72 - so it will wait for 7 days ? - So do we have to calculate the duration?
Please suggest me.
Thanks
Raghu

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2016 09:39 AM
It would be easiest to add a holiday schedule and use parent-child to exclude those dates. Then you only need to reference your one schedule and you use the system functionality instead of additional coding.
Check out the default schedule "8-5 weekdays excluding holidays" for an example.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-20-2016 09:59 AM
Hi Erik,
Thanks for the quick response,
I am using the default schedule only - 8-5 working excluding holidays -
When i am using that Schedule in the starting of my script in schedule job - I cannot see any email logs - Emails are not at all triggering when i click the execute action also. As i mentioned on the top when i used the below script in the condition then i can customise it in between the monday - friday only.
var answer = false;
//Get the day of week. 1=Monday, 7=Sunday
var now = new GlideDateTime();
//Run only on weekdays
if(now.getDayOfWeek() != 2){
answer = true;
}
answer;
I tried using the schedule like the below but still no luck.
var schedRec = new GlideRecord('cmn_schedule');
schedRec.get('name', 'M-F,7-5,Excluding Holidays');
var sched = new Packages.com.glide.schedules.Schedule(schedRec.sys_id);
if(sched.isInSchedule(gs.nowDateTime())){ Code here.....
Can u please suggest me how to get rid of the week end days. As i mentioned in the earlier example if an approval is requested on friday and it has t trigger the pending email on wednesday. (actually its 5 days but it has to take out the Sat & sun and then has to calculate the 3 days)
If we use the schedule then it will check only the Hours mentioned in the schedule - Eg: if 7-5 - 10Hrs / day so for 3 days its 24*3 = 72 - so it will wait for 7 days ? - So do we have to calculate the duration?
Please suggest me.
Thanks
Raghu