- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2022 02:49 AM
Hi,
We would also like to send notifications that would've been sent during a weekend or public holiday to be sent out to the user on the next workday.
Below is the code from schedule job that runs daily to send notification
The 'if' part is working, can anyone help on what should go into the 'else' part of the code to send notification on next working day.
Thanks!
var g = new GlideRecord('cmn_schedule');
g.addQuery('name', '8-5 weekdays excluding holidays');
g.query();
var days = gs.daysAgo(7).split(' ');
if (g.next()) {
var sched = new GlideSchedule(g.sys_id);
var d = new GlideDateTime();
d.setDisplayValue(days);
if (sched.isInSchedule(d)) {
//send notification toady - working
} else
//send notification on next working day - help!!
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2022 03:13 AM
If that is not the case then you can try using gs.eventQueueScheduled method which will schedule notification and you can use below logic.
var g = new GlideRecord('cmn_schedule');
g.addQuery('name', '8-5 weekdays excluding holidays');
g.query();
var days = gs.daysAgo(7).split(' ');
if (g.next()) {
var sched = new GlideSchedule(g.sys_id);
var d = new GlideDateTime();
d.setDisplayValue(days);
if (sched.isInSchedule(d)) {
//send notification toady - working
} else{
while(!sched.isInSchedule(d)){
d.addDaysLocalTime(1); //this will keep on adding days unless it is weekday
}
gs.eventQueueScheduled("event_name",current,"param1","param2",d); //with this method you can schedule notification which will trigger on next working day.
}
}
Let me know if you have any further queries.
Please mark this as Correct or Helpful if it helps.
Thanks and Regards,
Abhijit
Community Rising Star 2022
Regards,
Abhijit
ServiceNow MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2022 03:04 AM
Hi,
Not sure with your business case. However, if scheduled job is running daily then even if you just skip it over weekend, don't you think it will send that notification on working day when it executes when weekdays starts?
Let me know if you have any further queries.
Please mark this as Correct or Helpful if it helps.
Thanks and Regards,
Abhijit
Community Rising Star 2022
Regards,
Abhijit
ServiceNow MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2022 03:13 AM
If that is not the case then you can try using gs.eventQueueScheduled method which will schedule notification and you can use below logic.
var g = new GlideRecord('cmn_schedule');
g.addQuery('name', '8-5 weekdays excluding holidays');
g.query();
var days = gs.daysAgo(7).split(' ');
if (g.next()) {
var sched = new GlideSchedule(g.sys_id);
var d = new GlideDateTime();
d.setDisplayValue(days);
if (sched.isInSchedule(d)) {
//send notification toady - working
} else{
while(!sched.isInSchedule(d)){
d.addDaysLocalTime(1); //this will keep on adding days unless it is weekday
}
gs.eventQueueScheduled("event_name",current,"param1","param2",d); //with this method you can schedule notification which will trigger on next working day.
}
}
Let me know if you have any further queries.
Please mark this as Correct or Helpful if it helps.
Thanks and Regards,
Abhijit
Community Rising Star 2022
Regards,
Abhijit
ServiceNow MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-11-2025 02:01 AM
Hello @Abhijit4
I have a similar requirement. I need to send a notification every month on the second Monday. If the Monday happens to be a holiday, the notification should be sent on the next working day.
Could you please guide me on how to achieve this using Flow Designer?
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-11-2025 02:58 AM - edited ‎05-11-2025 11:46 PM
Hi @Mark Wood
If you are planning to write completely new flow just to achieve this notification functionality then I would suggest to go with scheduled job as it will require custom script and will take more efforts via flow.
Flow designer approach:
- Schedule Flow to be run on every weekday on Monday.
- Write custom script action in flow to verify today's Monday is 2nd Monday of month and not holiday ( with schedule )
- Trigger/skip notification accordingly.
Here is custom script that you would need either in flow or scheduled job ( recommend )
var now = new GlideDateTime();
var dayOfMonth = now.getDayOfMonthLocalTime();
var dayOfWeek = now.getDayOfWeekLocalTime(); // 1=Monday, 2=Tuesday, ..., 7=Sunday
// Check if it's the second Monday of the month
if (dayOfWeek == 1 && dayOfMonth >= 8 && dayOfMonth <= 14) {
var sched = new GlideSchedule("your_holiday_schedule_sys_id");
//This loop will automatically be skipped if its not holiday
while (sched .isInSchedule(now)) {
now.addDaysLocalTime(1); //this will keep on adding days until it is holiday
}
gs.eventQueueScheduled("event_name", current, "param1", "param2", now);
}
}
Regards,
Abhijit
ServiceNow MVP