
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
NOTE: MY POSTINGS REFLECT MY OWN VIEWS AND DO NOT NECESSARILY REPRESENT THE VIEWS OF MY EMPLOYER, ACCENTURE.
DIFFICULTY LEVEL: INTERMEDIATE
Assumes having taken the class SSNF and has good intermediate level of knowledge and/or familiarity with Scripting in ServiceNow.
From time-to-time the need arises at a client to have a scheduled email to be broadcast from their ServiceNow instance. This ability is actually pretty straightforward using a couple of mechanisms that are present in the out-of-the-box ServiceNow implementation.
The process is:
Lab 1.1: Create a New Event to Listen For
a. Navigate to Events > Registry
b. Click the New button
c. Fill in the form with the following:
- Event Name: notification.scheduled.daily
- Table: -- None --
- Fired By: Daily Notification scheduled job
- Description: Daily Notification to do timesheet
- Click on Submit to save your work.
Lab 1.2: Create a new Notification
a. Navigate to System Notification > Email > Notifications
b. Click the New button
c. Fill out the form with the following:
i. Name: Daily Notification Example
ii. Table: -- None --
iii. From the When to send tab:
A. Send when: Event is Fired
B. Event name: notification.scheduled.daily
C. Send to event creator: unchecked
NOTE: Table is mandatory when Send when is Record inserted or updated
d. Right-click on the top of the form and click Save on the context pop-up menu.
e. Scroll to the bottom of the form and in the Related Links click the Advanced View link.
f. Continue filling in the form:
i. From the Who will receive tab:
A. Event parm 1 contains recipient: checked
ii. From the What it will contain tab:
A. Content type: HTML only
B. Subject: Daily Timesheet Reminder!
C. Message HTML: Please remember to fill out yesterday's time in your timesheet!
D. Importance: High
g. Click on the Update button to save your work.
Lab 1.3: Create a New Scheduled Job
a. Navigate to System Definition > Scheduled Jobs
b. Click the New button
c. From the interceptor choose: Automatically run a script of your choosing
d. Fill out the form with the following:
i. Name: Daily Notification
ii. Run: Day
iii. Time: Hours: 06. This can be any time you want to send out the email.
iv. Run this script:
var getGroupByName = new GlideRecord('sys_user_group');
if (getGroupByName.get('name', 'Daily Notification Group')) {
gs.eventQueue('notification.scheduled.daily', null, getGroupByName.sys_id + '', null);
}
e. Right-click on the head and click save in the context menu.
Lab 1.4: Create the Distribution Group
a. Navigate to System Security > Users and Groups > Groups
b. Click the New button
c. Fill out the form with the following:
i. Name: Daily Notification Group
ii. Manager: (fill in with your favorite manager)
iii. Description: Team to be notified daily about timesheets
iv. Right click on the form head and click Save
v. Under the Group Members tab add the users you want to send the email to.
Lab 1.5: Testing!
a. Navigate to System Definition > Scheduled Jobs and pick the Daily Notification job you created.
b. Click on the Execute Now button.
c. Navigate to System Scheduler > Scheduled Jobs > Scheduled Jobs
d. Search for the Daily Notification job to verify that it is present.
e. Navigate to System Logs > Emails. Search for an entry where Subject is: Daily Timesheet Reminder! and open then most recent entry (should only be one right?)
f. Verify that the recipient list is the same as that in your group.
And that is all there is to it! 🙂
I want to highly recommend taking the ServiceNow Scripting training class should you get the opportunity. The class has an entire module covering Scheduled Job Scripting.
Enjoy!
Steven Bell.
If you find this article helps you, don't forget to log in and mark it as "Helpful"!
Originally published on: 7-4-2016 06:45 AM
I updated the code and brought the article into alignment with my new formatting standard.
- 2,189 Views
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.