How to run a Scheduled Job "daily" but exclude weekends

carlav
Kilo Guru

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!

find_real_file.png

1 ACCEPTED SOLUTION

Pranesh072
Mega Sage
Mega Sage

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 ;​

 

View solution in original post

6 REPLIES 6

Muralidharan BS
Mega Sage
Mega Sage

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

 

 

Pranesh072
Mega Sage
Mega Sage

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 ;​

 

Ankur Bawiskar
Tera Patron
Tera Patron

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

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Gunjan Kiratkar
Kilo Patron
Kilo Patron

Hi @carlav ,

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;

 

}


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy