The CreatorCon Call for Content is officially open! Get started here.

Scheduled job notification will not be sent on specific days

ofekg
Tera Contributor

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.

6 REPLIES 6

dhanrajb
Tera Guru

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.

GlideFather
Tera Patron

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! */


Juhi Poddar
Kilo Patron
Kilo Patron

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

 

 

Community Alums
Not applicable

@ofekg 

 

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:

  1. Open your Scheduled Script Execution.
  2. 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.