diff --git a/Server-Side Components/Scheduled Jobs/Adaptive Scheduler/Adaptive_Scheduler.js b/Server-Side Components/Scheduled Jobs/Adaptive Scheduler/Adaptive_Scheduler.js new file mode 100644 index 0000000000..8831d82785 --- /dev/null +++ b/Server-Side Components/Scheduled Jobs/Adaptive Scheduler/Adaptive_Scheduler.js @@ -0,0 +1,34 @@ +/*Adaptive-Scheduler +-------------------------------------------------------------- +- This script is intended to be added to the *Condition* field + of a Scheduled Report. +- Ensure the *"Advanced"* option checkbox is checked. +- Purpose: + * Run quarterly reports on the 2nd day of the quarter. + * If the 2nd day falls on a Friday, Saturday, or Sunday, + the report will instead run on the 5th day. +- Benefits: + * Ensures consistent quarterly reporting. + * Eliminates manual rescheduling for weekend conflicts. + * Maintains timely delivery of business insights. + ------------------------------------------------------------------------- +- Scheduled Report configuration + * Run: Monthly + * Day: 5 + ------------------------------------------------------------------------- +*/ + + + + +var start = false; //flag is declared +var gdt = new GlideDateTime(); // Create a GlideDateTime object for date calculations +gdt.addDays(-3); // Move back 3 days to simulate checking the 2nd day’s conditions +var dayOfWeek = gdt.getDayOfWeek(); // Get the day of the week (1 = Monday, 7 = Sunday) +var currentMonth = gdt.getMonthLocalTime(); + +if (((currentMonth % 3) == 2) && (dayOfWeek == '5' || dayOfWeek == '6' || dayOfWeek == '7')) { // Check if this is a quarterly month (February, May, August, November) + // if the 2nd day falls on a Friday (5), Saturday (6), or Sunday (7) + start = true; // Run on 5th if 2nd is Friday/weekend +} +start; diff --git a/Server-Side Components/Scheduled Jobs/Adaptive Scheduler/README.md b/Server-Side Components/Scheduled Jobs/Adaptive Scheduler/README.md new file mode 100644 index 0000000000..8f9c66f6f8 --- /dev/null +++ b/Server-Side Components/Scheduled Jobs/Adaptive Scheduler/README.md @@ -0,0 +1,30 @@ +🗓️ Adaptive Scheduler + +📘 Overview + +The Smart Quarterly Scheduler automates report execution for quarterly business reviews. It ensures that scheduled reports never fall on weekends or Fridays, maintaining consistent and reliable delivery. + +🧩 Problem Statement + +The business requires a quarterly report to run on the 2nd day of specific months (February, May, August, and November). However, when the 2nd day falls on a Friday or weekend, the client team will be typically on leave and may miss reviewing urgent reports. +This results in communication delays and missed insights during critical business periods. + +💡 Solution + +This script dynamically checks whether the 2nd day of the quarterly month is a Friday or weekend: + +If yes → the report automatically runs on the 5th day. + +If no → the report runs as usual on the 2nd day through another Scheduled Report. + +It uses GlideDateTime logic to determine execution dynamically within the Scheduled Report Condition. + +🚀 Benefits + +⏰ Minimizes manual scheduling effort + +✅ Ensures reports always run on valid business days + +📊 Maintains consistent quarterly performance insights + +🔁 Completely automated logic without admin dependency