Running a scheduled job every other month

mcarpenter
Tera Contributor

Hi All:

I have a requirement to have a scheduled job kick off the first day of odd number months (Jan, Mar, May, etc.). I am not sure where to start with this.   Should I try scripting an "on demand" run_type and then setting the condition to only run every other month? If so, could you help with how that script would look like?

Or should I try to create a new run_type that is bi-monthly or some other approach?   If so, what business rule do I need to modify?

Thanks for any help y'all are able to provide.

5 REPLIES 5

darius_koohmare
ServiceNow Employee
ServiceNow Employee

How about just setting it to run monthly, then check the condition box and in the conditional script add logic that checks if the current month number, and if its even return false, odd return true.


This will cause it just to run on odd months.


That was also going to be my suggestion - I've had exactly the same issue with cronjobs, and we ended up scheduling it for every month but even-numbered months (used MOD to determine the left-over) the job exited without any work performed.


ohhgr
Kilo Sage
Kilo Sage

Hi Michael,



You can set-up the Scheduled Job to run on a monthly basis. And add an if condition to check if current month is not divisible by 2. So, something like below should do the trick



if(new GlideDateTime().getMonthUTC() % 2 != 0) {


//your code here


}



Thanks,
Mandar


ananthagowraram
Mega Expert

Hi Michael,



For this scenario it is must be on demand type.Please try below steps



1) Get Current month from current date ex :2/21/2017 ; here we should be able to get month i.e 2


var gdt = new GlideDateTime(); //December


gs.print(gdt.getMonth());



The above code gives u numeric values like jan=1,feb=2



2) check if the values are odd ,then run the job