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

Hi,

The issue here though is that if you want it to run on the 2nd Monday, I'm not seeing that accounted for?

Also you seemed to have changed things to now run on the first month of the quarter, versus the 2nd month of the quarter as per your original post...?

The last piece of your if statement is looking at the date, but you set it to be less than or equal to 7, but the 2nd Monday for several months that this would land on...it would have been over the 7th.

So you may want to review the calendar fully to ensure this meets your requirement.

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Good catch, Allen!

The script was updated based on @oharel 's input, like this:

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

answer;

Validated here: https://www.webtoolkitonline.com/javascript-tester.html

Hi,

Alright. So it was really the assistance of the other poster that guided you correctly? As you have your own reply marked as Correct.

Not sure if you intended that, but if in the end, the author posts their own code, then they would always be correct, heh.

Anyways, your reply a few above this make it sound like placing the answer = false; initially...is what made it work. I think it was a combination of things, but ultimately...you are supposed to end the condition with a true or false outcome.

So ending with:

answer;

is what would assist in the conditional: https://developer.servicenow.com/dev.do#!/learn/learning-plans/orlando/new_to_servicenow/app_store_l...

Either way, the correct response may need to be adjusted now (whether to someone else's or your newer version...)

Take care!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!