The CreatorCon Call for Content is officially open! Get started here.

How to send notification reminder before 30days, 14 days and 7 days for incident

agadudasu
Tera Contributor

How to send notification reminder before 30days, 14 days and 7 days for incident

In incident has expiry date 

I want send reminder 

before 30 days 1 st reminder
              15 days 2 nd reminder
               7 days  3 rd reminder.

7 REPLIES 7

@svirkar420

the same link has already been shared earlier.

Any reason to share the same again and repeating as this might confuse the person who asked the question? 

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

MackI
Kilo Sage

Hi @agadudasu 

 

Based on your concept that the incident has an expiry date --

 

 

Step 1: Set up the incident expiry date field
First, ensure your incident table has the necessary fields for tracking expiry dates and reminder status:

Required fields on the incident table
Navigate to System Definition > Tables
Open the incident table
Add these fields:u_expiry_date (Date/Time) - The expiry date field
u_30_day_reminder_sent (Boolean) - Tracks 30-day reminder
u_15_day_reminder_sent (Boolean) - Tracks 15-day reminder
u_7_day_reminder_sent (Boolean) - Tracks 7-day reminder
These boolean flags prevent duplicate notifications from being sent at each interval.

Step 2: Register custom events in ServiceNow
Events provide a clean separation between the reminder logic and notification delivery

Navigate to System Policy > Events > Registry
Create three events:Event name: incident.expiry.30day Table: incident Description: Triggered 30 days before incident expiry
Event name: incident.expiry.15day Table: incident Description: Triggered 15 days before incident expiry
Event name: incident.expiry.7day Table: incident Description: Triggered 7 days before incident expiry
Step 3: Create the scheduled job for daily reminder checks
Configure the scheduled job
Navigate to System Definition > Scheduled Jobs 
Click New and select Automatically run a script of your choosing
Configure the job:Name: Incident Expiry Reminder Notifications
Run: Periodically
Repeat Interval: Daily
Time: 08:00:00 (or preferred off-peak time)
Active: true
Add the reminder check script
In the Script field, add this comprehensive script that handles all three reminder intervals:

(function executeExpiryReminderJob() {
var startTime = new GlideDateTime();
var stats = {
processed: 0,
notifications30Day: 0,
notifications15Day: 0,
notifications7Day: 0,
errors: 0
};

try {
// Process incidents with expiry dates
var gr = new GlideRecord('incident');
gr.addQuery('active', true);
gr.addQuery('u_expiry_date', '!=', '');
gr.addQuery('u_expiry_date', '>=', gs.nowDateTime()); // Not yet expired
gr.query();

while (gr.next()) {
stats.processed++;

try {
var expiryDate = new GlideDateTime(gr.u_expiry_date);
var currentDate = new GlideDateTime();

// Calculate days until expiry
var timeDiff = expiryDate.getNumericValue() - currentDate.getNumericValue();
var daysUntilExpiry = Math.floor(timeDiff / (1000 * 60 * 60 * 24));

// Check for 30-day reminder
if (daysUntilExpiry >= 29 && daysUntilExpiry <= 31 && !gr.u_30_day_reminder_sent) {
gs.eventQueue('incident.expiry.30day', gr, gr.assigned_to.toString(), gr.caller_id.toString());
gr.u_30_day_reminder_sent = true;
gr.setWorkflow(false); // Prevent triggering other workflows
gr.update();
stats.notifications30Day++;
gs.info('Sent 30-day reminder for incident: ' + gr.number);
}
Now, based on the above logic , complete the rest , i hope you can, isnt it :) Otherwise, use the Flow designer to trigger the event and notification

Step 4: Configure email notifications for each reminder
Create three notification records, one for each reminder interval: 
30-day reminder notification
Navigate to System Notification > Email > Notifications
Click New and configure: Incident Expiry - 30 Day Reminder
Table: Incident 
Active: true
Send when: Event is fired 
Event name: incident.expiry.30day 
Event parm 1 contains recipient: true (for assigned_to) 
Event parm 2 contains recipient: true (for caller_id) 
Subject: Reminder: Incident ${number} expires in 30 days

 

If you like this opinion and your problem is resolved after reviewing and applying it. Please kindly mark this your best answer‌🌠‌ OR  mark it  Helpful ‌‌ if you think that you get some insight from this content relevant to your problem and help me to contribute more to this community

MackI | ServiceNow Technical Consultant | DXC Technology Australia | ServiceNow Practice | LinkedIn Top IT Operation Voice 2023 | Sydney,Australia

MackI
Kilo Sage

hi @agadudasu 

 

Hope you are well. Did you look at to my answer or find a solution.

 

A small request from my end, If you like my opinion and your problem is resolved after reviewing and applying it. Please kindly mark this your best answer🌠‌ OR  mark it  Helpful ‌‌ if you think that you get some insight from this content relevant to your problem and help me to contribute more to this community

MackI | ServiceNow Technical Consultant | DXC Technology Australia | ServiceNow Practice | LinkedIn Top IT Operation Voice 2023 | Sydney,Australia