Using the schedule 8-5 weekdays excluding holiday in Scheduled job

sanjeev28 k
Giga Expert

I want my scheduled job to run only on business days.Can I use the schedule 8-5 weekdays excluding holiday in Scheduled job?

1 ACCEPTED SOLUTION

Jim Coyne
Kilo Patron

Here's code you can add to the Scheduled Job to verify if it should run or not:



var schedule = new GlideSchedule("090eecae0a0a0b260077e1dfa71da828");   //replace sys_id with the id of the appropriate schedule


if(schedule.isInSchedule(new GlideDateTime(gs.nowDateTime()))){


      //add your code here


    ...


}



It is an updated version of   Mark Stanger (Crossfuze)'s response here - The easiest way to do this



This line of code (not tested) should work directly in the Condition field of your Scheduled Job:



new GlideSchedule("090eecae0a0a0b260077e1dfa71da828").isInSchedule(new GlideDateTime(gs.nowDateTime()))


View solution in original post

3 REPLIES 3

Jim Coyne
Kilo Patron

Here's code you can add to the Scheduled Job to verify if it should run or not:



var schedule = new GlideSchedule("090eecae0a0a0b260077e1dfa71da828");   //replace sys_id with the id of the appropriate schedule


if(schedule.isInSchedule(new GlideDateTime(gs.nowDateTime()))){


      //add your code here


    ...


}



It is an updated version of   Mark Stanger (Crossfuze)'s response here - The easiest way to do this



This line of code (not tested) should work directly in the Condition field of your Scheduled Job:



new GlideSchedule("090eecae0a0a0b260077e1dfa71da828").isInSchedule(new GlideDateTime(gs.nowDateTime()))


Thank you Jim.



But I have one more question here.


My requirement is to generate a notification under 2 conditions for the change validation task.


                          a. Once the Validation Task "Requested End Date and Time" plus 4 calendar hours is reached.


                          b. This email notification will be re-sent to the Validation Task "Assigned to:" at 8, 16, and 24 business hours past the Task                           "Requested End Date and Time".




how can i achieve this.I have lots of confusion regarding this calculation.




if(parseInt(reqEndYear) == parseInt(curYear))


    {


    if(parseInt(reqEndMonth) == parseInt(curMonth))


    {


    gs.log("**Task on the same day " + valtask.number + "Current date " + curDate + "End Date " + reqEndOnlyDate);


    if(parseInt(reqEndOnlyDate) == parseInt(curDate))


    {


          if(parseInt(reqEndHrs) + 1 == parseInt(curHour) || parseInt(reqEndHrs)+8 == parseInt(curHour) || parseInt(reqEndHrs)+16 == parseInt(curHour)){


          gs.eventQueue("change_task.escalation.fired",valGr,taskAssignedTo,reqEndDate);


    }


   


    }


   


    }


   


    }


I edited my post to add "gs.nowDateTime()" to the code in order to get the date/time back in the appropriate timezone.   Without it, the date/time returned is based on GMT timezone, which could throw things off.