Scheduled Job to run on a quarterly basis

Luiz Lucena
Mega Sage

Hello everyone, 

There is a scheduled job created to run every second month of each quarter, it should run at the second Monday of the second month. 

I have a feeling that the conditions created in the scheduled job will run every Monday, every week...
Take a look:
find_real_file.png

(new Date().getMonth() == 2 || new Date().getMonth == 5 || new Date().getMonth == 8 || new Date().getMonth == 11) && (new Date().getDate() <= 7);
answer = true;

How should we put the conditions here?

Thanks,

1 ACCEPTED SOLUTION

We did this and is working now.

 

var answer = false;
if ((new Date().getMonth() == 1 || new Date().getMonth() == 4 || new Date().getMonth() == 7 || new Date().getMonth() == 10) && (new Date().getDate() <= 7)) 
    answer = true;

answer;


What made work was declaring the variable answer as false in the beginning, so if the conditions doesn't match, the job won't run.

View solution in original post

7 REPLIES 7

oharel
Kilo Sage

hi Luiz,

Why not run it Periodically instead of Weekly? Leave the condition as it is...

hare;

Come to think of it, you also want to run it on the second Monday or the month, so I think you will also have to add to the condition:

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

getDay()==1 this will check for a Monday

new Date().getDate() > 7 && new Date().getDate() =< 14 this should get the second Monday. I did not try it, so check it before implementing.

//Sunday (0), Monday (1), Tuesday (2), Wednesday (3), Thursday (4), Friday (5), Saturday (6)

Pedro Grilo1
Mega Sage

Hi!

 

To check the month condition you could have something like:

var answer = false;
var date = new GlideDate();
var month = date.getMonthLocalTime();
if(month == 2 || month  == 5 || month  == 8 || month  == 11) {
	//Check for the day of week condition
}


I would also check the post below on how to get the second Tuesday of each month:

https://community.servicenow.com/community?id=community_question&sys_id=8cee83a1dbdcdbc01dcaf3231f961945

 

Best regards

We did this and is working now.

 

var answer = false;
if ((new Date().getMonth() == 1 || new Date().getMonth() == 4 || new Date().getMonth() == 7 || new Date().getMonth() == 10) && (new Date().getDate() <= 7)) 
    answer = true;

answer;


What made work was declaring the variable answer as false in the beginning, so if the conditions doesn't match, the job won't run.