In the project I’m currently working are multiple reports scheduled. Some of my colleagues receive more than 20 of those mails daily. Most of them on a periodical basis. Also on the weekend and in the night, where they weren’t required or even necessary, they only flood the mailbox. Some of them then asked me, how this can be adjusted so the reports will only be sent on the weekdays. I’ve therefore searched and adjusted a condition script to exclude the weekends. However, the script was sometimes working and sometimes not (it was correct though).
I’ve then searched more in detail and found something even better – a condition script to only send mails in a schedule AND in a specific time zone, since most of my colleagues are located all over the world and only a hand full in Germany.
The best on this solution: it’s suggested from ServiceNow! Not a script from the community or even developed on my own.
In the below list there’s the procedure how to use the condition script:
1. Create a Schedule (System Scheduler > Schedules), or use an existing Schedule in your system
2. Add the ‘Conditional’ and ‘Condition’ fields to your Scheduled Reports form
3. Check the ‘Conditional’ checkbox
4. Set ‘Run’ to Periodically, then set an hour interval you wish to have the report sent out with
5. In the ‘Condition’ field, use the following script (replace the timezone with your timezone, replace the 32-character sys_id with the sys_id of the Schedule you created – you can get that by right-clicking it in the Schedules list and selecting Copy sys_id
var s = new GlideSchedule("<sys_id of the scheudle>"); var gdt = new GlideDateTime(); s.isInSchedule(gdt, "<the target time zone>");
var s = new GlideSchedule("08fcd0830a0a0b2600079f56b1adb9ae"); var gdt = new GlideDateTime(); s.isInSchedule(gdt, "US/Pacific");
To get the list of schedules, you can use the below link (simply set your instance suffix) or use the application menu method:
System Scheduler > Schedules > Schedules
Time zones are not available in a central table. They’re stored as choice list options. There are several ways how to access the available tables. You can use the below link (adjust the ServiceNow instance name):
I hope this solution helps you and your colleagues as it helps me and my colleagues.