Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

Omkar Mone
Mega Sage

Have you been able to think of creating a schedule for this that will make the scheduled job run on that schedule?

Aniket Chavan
Tera Sage
Tera Sage

Hello @ofekg ,

Please try to use the code below and see & let me know how it works for you.

 

// Get the current day of the week (1 = Sunday, ..., 7 = Saturday)
var currentDay = new GlideDateTime().getDayOfWeek();

// Skip sending notifications if it's Friday (6) or Saturday (7)
if (currentDay === 6 || currentDay === 7) {
    gs.info('Notification skipped as today is Friday or Saturday.');
    return;
}

// Query open incidents
var openIncidents = new GlideRecord('incident');
openIncidents.addQuery('state', 'open');
openIncidents.query();

// Send notifications for open incidents
while (openIncidents.next()) {
    gs.eventQueue('incident.daily.notification', openIncidents, openIncidents.sys_id, gs.getUserID());
}

 

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.


Regards,
Aniket