Scheduled job notification will not be sent on specific days
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2024 12:24 AM
I have a Scheduled Script Execution for Daily Notification For Open Incidents.
it runs daily on 10:00 am.
How to add a condition so that the notification will not be sent on Fridays and Saturdays.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2024 12:51 AM
Hi @ofekg ,
You can simply add a condition before your whole script like below. So the scheduled job won't run on Fridays and saturdays.
var dateTime = new GlideDateTime();
var weekOrder = dateTime.getDayOfWeekUTC();
if(weekOrder != 5 || weekOrder != 6){
//run your existing script
}
Regards,
Dhanraj.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2024 12:58 AM
Firstly, check the system property of the week's first day of your instance.
Whether it is Sunday or Monday:
- If Sunday > Sunday 0, Monday 1, Tuesday 2, ... Saturday 6
- If Monday > Monday 0, Tuesday 1, Wednesday 3, ... Sunday 6
Then try to use something like this:
var today = new Date();
var dayOfWeek = today.getDay();
//Use (4 and 5) or (5 and 6) as seen above
if (dayOfWeek === 4 || dayOfWeek === 5) {
//write your code
return;
}
/* If my response wasn’t a total disaster ↙️ ⭐ drop a Kudos or Accept as Solution ✅ ↘️ Cheers! */
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2024 06:28 AM
Hello @ofekg
Here’s an example of how you can implement this logic within your Scheduled Script Execution:
(function() {
var gdt = new GlideDateTime();
var dayOfWeek = gdt.getDayOfWeek(); // 1 = Sunday, 2 = Monday, ..., 6 = Friday, 7 = Saturday
// Check if today is Friday (6) or Saturday (7)
if (dayOfWeek == 6 || dayOfWeek == 7) {
gs.print('Notification will not be sent today as it is Friday or Saturday.');
return; // Exit the script without sending the notification
}
// Your existing notification logic here
var gr = new GlideRecord('incident');
gr.addQuery('state', 'open');
gr.query();
while (gr.next()) {
// Send the notification for each open incident
gs.eventQueue('incident.open.notification', gr, gr.sys_id, gs.getUserID());
}
gs.print('Daily notification sent for open incidents.');
})();
Hope this helps!
"If you found my answer helpful, please like and mark it as an "accepted solution". It helps others find the solution more easily and supports the community!"
Thank You
Juhi Poddar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2024 08:59 PM
You can modify your Scheduled Script Execution to include a condition that checks the current day of the week before sending the notification. Here's how you can do it:
- Open your Scheduled Script Execution.
- Add the following script to check the day of the week:
var currentDay = new GlideDateTime().getDayOfWeek(); // Get the current day of the week (1 = Sunday, 7 = Saturday) if (currentDay != 6 && currentDay != 7) { // 6 = Friday, 7 = Saturday // Your existing code to send the notification gs.info('Sending notification for open incidents'); // Add your notification code here } else { gs.info('No notification sent today as it is Friday or Saturday'); }
This script checks if the current day is Friday (6) or Saturday (7). If it is, the notification will not be sent. Otherwise, it will proceed with sending the notification.
Make sure to test this in a development instance to ensure it works as expected.
Important Note
If you found this response helpful, please select 'Accept as Solution' and mark it as 'Helpful.' Your support acknowledges my effort and helps enhance our community.