Periodical Scheduled Reports: only send on Workdays in Business Times

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

Script:

var s = new GlideSchedule("<sys_id of the scheudle>");
var gdt = new GlideDateTime();
s.isInSchedule(gdt, "<the target time zone>");

Example:

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:
https://<instance>.service-now.com/cmn_schedule_list.do
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):
https://<instance>.service-now.com/slushbucket_choice.do?sysparm_ref=sys_user.time_zone&sysparm_form=sys_choice&sysparm_dependent=&sysparm_stack=no

I hope this solution helps you and your colleagues as it helps me and my colleagues.

Related Links:

Plugin: WebKit HTML to PDF

Today I want to introduce you to a small, but very useful ServiceNow plugin: WebKit HTML to PDF. The name is not very meaningful, so I want to tell you something about this plugin.

The plugin WebKit HTML to PDF is used to provide users the ability to export homepages and dashboards as PDF documents. This is a very useful tool for your daily work. But keep in mind, that this is only an extract and will not be updated, unlike homepages or dashboards.

Note: When you activate this plugin, OAuth 2.0 will be activated as well if not already installed.

ID: com.snc.whtp
Price: Free
Producer: ServiceNow

Roles required
admin

It’s very simple to activate this plugin. I’ll explain what functions the plugin offers and how it is activated.

Before the plugin is actived, lets view the homepage. The homepage (dashboards as well) do not offer any functions to export the visible information to PDF.

Homepage before plugin activation.

Let’s activate the plugin. Plugins are listed in the System Definitions -> Plugins module. In the content frame, search for ‘WebKit HTML to PDF’. Now you can simply klick on Install to install this plugin.

Plugins module.

Before the plugin will be installed, you’ll receive a prompt to finally activate the plugin. Dependent plugins are also shown. For the WebKit HTML to PDF the dependent plugin OAuth 2.0 is necessary and will be automatically activated.

Activation plugin WebKit HTML to PDF.

After you clicked on activate, the plugin will be installed.
Please be careful, activating a plugin can affect performance to your inctance, so I recommend to activate the plugin outside the business hours in order not to impair other users of the systemt.

Activation state of plugin.

The activation is finished in a short time. You have the ability to view the activation log, plugin list or simply close & reload the form to use the functions of the plugin.

Activation result.

In the Plugin Application Logs, the changes are listed which are made to install the plugin.

Plugin Activation Log 1.
Plugin Activation Log 2.

After the installation is completed and the whole website has been refreshed, you can go back to your default landing page and you’ll note a new icon in the banner of the content frame of homepages and dashboards. When you click on this icon, a pop up appears.

Homepage after activation.

The popup ‘Export to PDF’ offers the possibility to define certain frame criteria.
You can devine the Orientation of the export, portrait or landscape. Also the paper size and zoom factor can be set.
A very nice feature is, you can decide between directly generate and download the PDF, or send the PDF export by email to specified recipients.

Export to PDF.

When you select the option to generate the PDF right now, after a few seconds when the export has completed, the PDF can be downloaded.

Export complete, download.

The exported and downloaded PDF file, is shown in the image below for the ITIL Homepage. It’s generated as a letter sized file and all information at the time of export are visible.

PDF export of homepage.

The activation of this plugin has no impact to your instance, it only provides you the ability to simply export dashboards and homepages to PDF.