Facing issues to run a condition if the Scheduled Job
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2025 02:10 AM
Hi Team, I am facing one issue to find a logic in Scheduled Job.
The requirement is to only RUN the IF condition, if it is a weekday (Mon-Fri) or there is a holiday on any weekday. Eg- Jan 01 was on Wednesday, so the IF condition should not run.
But after multiple tries, I couldn't get the solution, so will be grateful, if anyone can help.
Attaching the snippet I tried :-
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2025 11:04 AM
Hello @p_mriganka
Some changes to your code will make it work.
Logic Inversion: Changed holidays.includes() to !holidays.includes() (only run on weekdays that are NOT holidays)
Day of Week Numbers:
Monday = 1
Friday = 5
Saturday = 6
Sunday = 0
Refined code now:
var currentDay = new GlideDateTime().getDayOfWeekLocalTime(); // 1=Mon, 5=Fri, 6=Sat, 0=Sun
var currentDate = new GlideDateTime().getLocalDate().toString();
var currentMonthDay = currentDate.substring(5); // Get MM-DD format
var holidays = ["01-01", "01-26", "08-15", "10-02"];
// Check if it's a weekday AND NOT a holiday
if (currentDay >= 1 && currentDay <= 5 && !holidays.includes(currentMonthDay)) {
// YOUR CODE TO EXECUTE ON WORKING WEEKDAYS
gs.print("Running business logic for " + currentDate);
} else {
gs.print("Skipping execution - Weekend or holiday");
}
If my response has helped you hit helpful button and if your concern is solved do mark my response as correct.
Thanks & Regards
Viraj Hudlikar.