- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2021 03:06 AM
I need to create Scheduled Jobs following a script we created that initiates a Catalog Item, and the Scheduled Job needs to run daily and exclude weekends but I don't see how to select Daily excluding weekends. Any suggestions/direction would be appreciated!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2021 03:15 AM
Check the conditional field and add following script
var result = true;
var gdt = new GlideDateTime();
var day = gdt.getDayOfWeekLocalTime(); //The day of week value from 1 to 7. Monday equals 1, Sunday equals 7.
if(day==6||day==7)
result =false;
result ;​

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2021 03:14 AM
Hi Carlav,
One of the way to achieve this using Glide Schedule. you can click the conditional and apply this script.
example like below,
checkSchedule();
function checkSchedule(){
var now = new GlideDateTime();
var insched = new GlideSchedule("123456"); //sysid of schedule
insched.setTimeZone('Europe/London');
if (insched.isInSchedule(now)){
return true;
}
else{
return false;
}
}
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2021 03:15 AM
Check the conditional field and add following script
var result = true;
var gdt = new GlideDateTime();
var day = gdt.getDayOfWeekLocalTime(); //The day of week value from 1 to 7. Monday equals 1, Sunday equals 7.
if(day==6||day==7)
result =false;
result ;​
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2021 03:16 AM
Hi,
Set the Conditional Checkbox as true
In the condition field give this script
answer = checkCondition();
function checkCondition(){
var gdt = new GlideDateTime();
// if the day of week is not 6 and not 7 it means it is weekday
if(gdt.getDayOfWeelLocalTime() != 6 && gdt.getDayOfWeekLocalTime() != 7)
return true;
else
return false;
}
Regards
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
‎02-22-2021 03:17 AM
Hi
In Scheduled Jobs please enable the Condition checkbox and paste the below code.
var answer = false;
var now = new GlideDateTime();
if(now.getDayOfWeekUTC() !=6 && now.getDayOfWeekUTC() !=7 ) // this scheduled job will run only on Weekdays
{
answer = true;
}