Scheduled Job Condition - First Monday of Every Month

tyler_ford
Giga Contributor

I have a number of tasks that I am looking to assign to IT members using scheduled jobs in Service Now.   I would like to create a monthly schedule that will run on the first Monday of every month as most do not work on weekends.   Has anybody had success creating a schedule like this?    

1 ACCEPTED SOLUTION

Right, but the requirement is for the first Monday of the month.   The isFirstDayOfWeek method simply tells you if it is a Monday or not.



This condition should work:


new Date().getDay() == 1 && new Date().getDate() <=7



It checks to see if it is a Monday (new Date().getDay() == 1) and if it is less than or equal to 7 days into the month (new Date().getDate() <=7).


View solution in original post

20 REPLIES 20

Right, but the requirement is for the first Monday of the month.   The isFirstDayOfWeek method simply tells you if it is a Monday or not.



This condition should work:


new Date().getDay() == 1 && new Date().getDate() <=7



It checks to see if it is a Monday (new Date().getDay() == 1) and if it is less than or equal to 7 days into the month (new Date().getDate() <=7).


Yeah..I was seriously out of my mind.thanks for pointing it out.Your code seems to do exactly what is required.


Hi Jim.   Istanbul seems to have a problem with the code, eg "Expected and assignment of a function call and instead saw an expression".   I'm a little weak on syntax sometimes especially with type of code.   Is this syntax warning something I just ignore for a Scheduled Job Condition statement?   Please forgive me if a lame question.



~Paul


Do you mean in the form view when you hover over the little exclamation point icon:find_real_file.png



That is actually fine, the record will save and will run as long as the condition is true.   It's a problem with how the script has to return the value, but it will evaluate properly for you.


Apologies for the delay Jim.   Yes... exactly.   And... thanks again!