How to Scheduled job conditional dates

Joshua Comeau
Kilo Sage

I am looking to make an adjustment to a Scheduled jobs which run monthly and quarterly basis.

 

The monthly runs monthly,

 

But it is not required on the quarterly schedules run on, which is in the months of January, April, July and October.

 

Is there a conditional clause that that would tell the monthly jobs not to run on months when the quarterly jobs run?

 

What I am thinking is to make a condition in the script to tell it to not run the monthly one on certain months you specify, this is where my head is at. 

 

Their is a condition checkbox on the form how to script this?

3 ACCEPTED SOLUTIONS

SN_Learn
Kilo Patron
Kilo Patron

Hi @Joshua Comeau ,

 

You need to check the condition box and write a script to identify the month. If those conditions will be satisfied then job will run else it won't run.

 

 

 

function checkMonth()

{
var gd = new GlideDateTime();
var getMonth = gd.getMonth();

//Here, 1 is January and 12 represent December
//Update months as per your requirement
if(getMonth == 1 || getMonth == 12) {
return true;
}
else{
return false;
}}

 

 

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.

View solution in original post

//Return 'true' to run the job

var answer = false;

 

//Get the month of the year. 1=January, 12=December

var now = new GlideDateTime();

 

//Run quarterly

month = now.getMonth();

if(month == 1 || month == 4 || month == 7 || month == 10){

   answer = true;

}

answer;

 

was looking for an example towards the script from this would this work?

View solution in original post

Thanks @Joshua Comeau for marking helpful. Could you please also accept it as solution, as multiple answers could be marked as solution if the solution helped.

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.

View solution in original post

5 REPLIES 5

SN_Learn
Kilo Patron
Kilo Patron

Hi @Joshua Comeau ,

 

You need to check the condition box and write a script to identify the month. If those conditions will be satisfied then job will run else it won't run.

 

 

 

function checkMonth()

{
var gd = new GlideDateTime();
var getMonth = gd.getMonth();

//Here, 1 is January and 12 represent December
//Update months as per your requirement
if(getMonth == 1 || getMonth == 12) {
return true;
}
else{
return false;
}}

 

 

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.

//Return 'true' to run the job

var answer = false;

 

//Get the month of the year. 1=January, 12=December

var now = new GlideDateTime();

 

//Run quarterly

month = now.getMonth();

if(month == 1 || month == 4 || month == 7 || month == 10){

   answer = true;

}

answer;

 

was looking for an example towards the script from this would this work?

@Joshua Comeau yes, looks good. You can try it. Instead of answer, try with return true or false.

I have attached a script in the above response.

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.

Thanks @Joshua Comeau for marking helpful. Could you please also accept it as solution, as multiple answers could be marked as solution if the solution helped.

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.