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

Are those custom functions?   Can't say that I've seen them before.



And I'm wondering about the logic, and really just guessing because I have not seen the code, but what happens when the first Monday is in the second week of the month?


Bad example. There is actual 2 that could fire. 1 if in first week, another if in 2nd week. Totally different templates. But we use that code in many cases.


Hi Jim,



I want to use getDay() to my date field which is a field input by user. When user selects any day but Monday, it should throw error message.



This is what i am trying to do:


var selected_date = g_form.getValue('week_starts');


var dObj = new Date(selected_date);


alert('new date '+dObj);


var selected_day = dObj.getDay();


//alert(selected_day);


  if(selected_day==1){


  return true;


  }


else{


//message


}



But here dObj returns NaN.



I have also tried:


var selected_day = g_form.getValue('week_starts').getDay();



This also does not work. Please suggest how can i use the getDay() function in this scenario.


Is this in a regular form or a Service Catalog item?   I'm assuming you want to validate the value right after the user selects a new date?   What version of the platform?


I have written this logic in a catalog client script and i am validating when user clicks on Submit button.


When user clicks on Submit, if the date selected is not monday ot should abort the submission and ask user to select Monday.



As long as the date format is "system (yyyy-mm-dd)", there is no issue but if some user has different date format selected in their profile, it validates wrong and even if selecting monday, it does not let the form submit. I checked the log and it gives undefined value.



My Service Now is in FUJI patch-9 version currently.


Any help will be much appreciated.




Thanks,


Anupama