- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2021 06:33 AM
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:
(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,
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2021 02:55 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2021 06:46 AM
hi Luiz,
Why not run it Periodically instead of Weekly? Leave the condition as it is...
hare;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2021 06:57 AM
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)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2021 06:54 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2021 02:55 PM
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.