- 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:30 AM
the issue is with holidays on weekdays, then we need to send the notification next day. Say if the record was created 7 business days ago and there isn't any activity on it so we will send notification to assigned to person. But if after 7 business days its a holiday/weekend then how will we send the notification next day?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2022 03:45 AM
My script part will work to scheduled notification. Whenever scheduled job runs over weekend then above script will schedule notification which will be run on next weekday.
To consider holiday, you would need to create holiday schedule and use it in scheduled job.
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