- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2023 08:43 AM
Hey all!
I have to update a scheduled job to run periodically (every 80 days) while excluding weekends. However, if the 80th day falls on a weekend, I need the job to run on the first weekday immediately after. The "Conditional" checkbox is selected, "Periodically" is selected in the "Run" field, and "Repeat Interval" is set to 80 days.
My question is - will the scheduled job run on the first weekday following a weekend automatically if the weekend is skipped, or do I have to include something in my script to accomplish that?
Please see my current script below. Any help is much appreciated. Thank you!
var result = true;
var gdt = new GlideDateTime();
var day = gdt.getDayOfWeekLocalTime(); //The day of week value from 1 to 7. Monday equals 1, Sunday equals 7.
if (day == 6 || day == 7)
result = false;
result;
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2023 09:03 PM
HI @nlopez4 ,
I trust you are doing great.
Please find the updated code .
var result = true;
var gdt = new GlideDateTime();
// Get the day of the week (1=Monday, 7=Sunday)
var day = gdt.getDayOfWeekLocalTime();
// Check if today is Saturday (6) or Sunday (7)
if (day == 6 || day == 7) {
// Calculate days to add (1 day if Sunday, 2 days if Saturday)
var daysToAdd = (day == 7) ? 1 : 2;
// Add the days to the current date
gdt.addDaysLocalTime(daysToAdd);
// Schedule the job for the next weekday
current.setValue('next_action', gdt.getValue());
result = false;
}
result;
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2023 09:03 PM
HI @nlopez4 ,
I trust you are doing great.
Please find the updated code .
var result = true;
var gdt = new GlideDateTime();
// Get the day of the week (1=Monday, 7=Sunday)
var day = gdt.getDayOfWeekLocalTime();
// Check if today is Saturday (6) or Sunday (7)
if (day == 6 || day == 7) {
// Calculate days to add (1 day if Sunday, 2 days if Saturday)
var daysToAdd = (day == 7) ? 1 : 2;
// Add the days to the current date
gdt.addDaysLocalTime(daysToAdd);
// Schedule the job for the next weekday
current.setValue('next_action', gdt.getValue());
result = false;
}
result;
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2023 09:33 AM
Hi Amit,
Thank you for your help! Take care and stay well!