Send Email Periodically 1 Hour for specific Time
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi, I have requirement to send email by using Scheduled Email Report every 1 hours but specifically between office hour 8AM until 8PM daily. Anyone can provide script or guidance on how to fulfill this requirement?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
I have tested in our dev instance. it is working (sending every 1 hour between 8am - 8pm). But when apply the same script into actual scheduled email report at our production instance, it is not working (sending every 1 hour full day 24x7).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
I have update the script to
var gdt = new GlideDateTime();
var hour = gdt.getTime().getHourOfDayLocalTime();
answer = (hour >= 7 && hour < 20);and now its working. Might related to timezone
Thanks for your help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
Glad to know.
Please mark my earlier response with script as correct to close the thread.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @Muhammad Arif B ,
check here -> https://www.servicenow.com/docs/bundle/zurich-now-intelligence/page/use/reporting/task/t_ScheduleARe...
script :-
// Get current system time and convert to local display string
var now = new GlideDateTime();
var displayTime = now.getDisplayValue();
// Use substring to grab the two-digit hour directly from 'YYYY-MM-DD HH:mm:ss'
// The hour starts at character index 11
var hour = parseInt(displayTime.substring(11, 13), 10);
// Set answer to true only if the hour is between 8 (8 AM) and 19 (7:59 PM)
if (hour >= 8 && hour < 20) {
answer = true;
} else {
answer = false;
}
