- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2024 06:13 AM
I have the following Scheduled job. It should run on the second monday of each month. If I take the conditional code and run it in scripts background (and replace with return with gs.print('true') or gs.print('false') respectively). I get the correct response, with true or false. These should run every monday of the month due to having multiple jobs that have the same criteria of 1st, 2nd, 3rd, 4th mondays (each monday will run a different job). If I execute from the UI Action button it runs. If I set a time for like 15 minutes in the future on the given date it runs. However it does not run as it should. Please help! Am I doing something wrong with the condition? It's hard to troubleshoot this as it's only running the x number monday of the month.
Here is the scheduled Job
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2024 04:01 AM - edited 06-12-2024 04:08 AM
Hi @Community Alums , I worked on similar kind of requirement in past, Please find below code it will trigger only on 2nd Monday of the month, I tested it, Its working fine. use it in condition script of scheduled job.
function getweekofmonth() {
var gdt = new GlideDateTime();
//gs.print(gdt);
var day = gdt.getDayOfMonthLocalTime();
var dayOfWeek = gdt.getDayOfWeek();
var weekOfMonth = Math.floor((day - 1) / 7) + 1;
if (dayOfWeek === 1 && weekOfMonth === 2) {
// gs.print("Scheduled Job will Run");
return true;
} else {
// gs.print("Scheduled Job will NOT Run");
return false;
}
}
getweekofmonth();
If my response helped you, please click on "Accept as solution" and mark it as helpful.
Thanks
Suraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2024 04:01 AM - edited 06-12-2024 04:08 AM
Hi @Community Alums , I worked on similar kind of requirement in past, Please find below code it will trigger only on 2nd Monday of the month, I tested it, Its working fine. use it in condition script of scheduled job.
function getweekofmonth() {
var gdt = new GlideDateTime();
//gs.print(gdt);
var day = gdt.getDayOfMonthLocalTime();
var dayOfWeek = gdt.getDayOfWeek();
var weekOfMonth = Math.floor((day - 1) / 7) + 1;
if (dayOfWeek === 1 && weekOfMonth === 2) {
// gs.print("Scheduled Job will Run");
return true;
} else {
// gs.print("Scheduled Job will NOT Run");
return false;
}
}
getweekofmonth();
If my response helped you, please click on "Accept as solution" and mark it as helpful.
Thanks
Suraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2024 06:30 AM
Worked great, thank you