Email Notification based on Scheduled job
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2023 08:54 PM
Hello,
Hoping I can get some assistance:
I have a requirement to send a notification to Change Managers when a Standard Change Template is nearing expiration (there is an expiration date field).
The intervals from expiration are:
20 days
15 days
7 days
6 to 1 (every day until expiration)
0 - notify that a template has expired
The notification template is:
SUBJ:
Standard change template [template name] will expire in XX days / has expired
BODY:
Hi [Change manager name],
The Standard Change template [template name] in ServiceNow will expire in XX days / has expired, please review the template before [expiry date].”
I have created a scheduled job and an event (attached).
I am a very new to scripting, would someone be able to assist in how the email notification should be set.
Do I need an email script or can it be done through the email notification form?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2023 09:44 PM
HI @cjv ,
I trust you are doing great.
you can achieve this by using a scheduled job and an email script. Let's break it down step by step:
Scheduled Job:
- Create a scheduled job in ServiceNow that runs at regular intervals (e.g., once a day).
- This job will check the expiration date of each Standard Change Template and trigger the appropriate email notification.
Email Script:
- Create an email script that will generate the email notification.
- Here's an example of how the script might look in ServiceNow's scripting language (JavaScript):
// Fetch the Standard Change Templates nearing expiration
var templateGr = new GlideRecord('standard_change_template');
templateGr.addQuery('expiration_date', '>=', gs.daysAgo(-20)); // Adjust the number of days as per your requirements
templateGr.addQuery('expiration_date', '<=', gs.daysAgo(0));
templateGr.query();
while (templateGr.next()) {
var expirationDate = templateGr.getValue('expiration_date');
var daysUntilExpiration = gs.daysBetween(gs.nowDateTime(), expirationDate);
// Determine the appropriate email subject and body based on the expiration interval
var subject = "Standard change template " + templateGr.getValue('name') + " will expire in " + daysUntilExpiration + " days / has expired";
var body = "Hi [Change manager name],\n\nThe Standard Change template " + templateGr.getValue('name') + " in ServiceNow will expire in " + daysUntilExpiration + " days / has expired, please review the template before " + expirationDate + ".";
// Send the email to the Change Manager
gs.eventQueue("email.send", templateGr.getRecordClassName(), templateGr.getUniqueValue(), subject, body, templateGr.getValue('change_manager'));
}
- Email Notification Form:
- You can use the email script within an email notification form to define the content and format of the email being sent.
- Create an email notification in ServiceNow and reference the email script you created in the previous step.
- This form allows you to customize the email layout, add additional fields, and control other email settings.
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2023 10:26 PM
Email Notifications can be sent from Scheduled Jobs in ServiceNow
- This can be done through the use of the GlideSysMail class
- The GlideSysMail class can be used to set up an email notification to be sent from a Scheduled Job.
- The GlideSysMail class requires a few parameters to be set up in order to send the notification including the recipient, subject, message, and from address
- Once the parameters are set up, the GlideSysMail class can be used to send the email notification from the Scheduled Job
For asking ServiceNow-related questions try this :
For a good and optimistic result, please visit this website. It uses a Chat Generative Pre-Trained Transformer ( GPT ) technology for solving ServiceNow-related issues.
Link - https://nowgpt.ai/