Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Scheduled Job with conditional script

Brian Lancaster
Kilo Patron

We have a scheduled job that was created by the vendor.  It runs every hour on incidents table.  I has conditional check with the following script to prevent it to run on Saturday and Sunday.

//Apply only on Weekday
   var dateVal = new Date();
    var weekday = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
    var day = weekday[dateVal.getDay()];
if( day != "Sunday" && day != "Saturday"){
	answer = true;
}

Because this is an automated 3 strike rule and we have holidays that don't count towards are SLA we would also like to prevent the 3 strike rule from running on Holidays.  How can I modify this script so that it also does not run on holidays?

1 ACCEPTED SOLUTION

sachin_namjoshi
Kilo Patron
Kilo Patron

You will have to run scheduled job based on schedule

check below

 

https://community.servicenow.com/community?id=community_question&sys_id=d31ecfaddb9cdbc01dcaf3231f96...

 

 

Regards,

Sachin

View solution in original post

4 REPLIES 4

sachin_namjoshi
Kilo Patron
Kilo Patron

You will have to run scheduled job based on schedule

check below

 

https://community.servicenow.com/community?id=community_question&sys_id=d31ecfaddb9cdbc01dcaf3231f96...

 

 

Regards,

Sachin

Other then having to fix the logic in his if statement it seems to be working.

checkInSchedule();

function checkInSchedule(){

var schedRec = new GlideRecord('cmn_schedule');

schedRec.get('8-5 weekdays excluding holidays');

if(typeof GlideSchedule != 'undefined')

var sched = new GlideSchedule(schedRec.sys_id);

var inSched = sched.isInSchedule(new GlideDateTime());

if(inSched){

return true;

}

else{

return false;

}

}

the holiday days shall be type "excluded" in the cmn_schedule table? and what does isInSchedule() returns then if the days are of type "excluded" in cmn_schedule?: my scenario is to run the job on every 11th business day of a month, it should check the condition if there is a UK holiday it must exclude it as well.

asifnoor
Kilo Patron

You can fix the condition like this 

//Apply only on Weekday
   var dateVal = new DateTime();
   if(dateVal.getDayOfWeek() <=5) {
      return true;
    } else {
      return false;
    }
   

Hope this helps.