notification needs to be send everyday for 7 days
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2023 01:15 AM
we have to develop a notification which needs to be triggered 7 days prior to the leave end date (which we are getting from a catalog and client will be providing that date ).the notification should trigger everyday for 7 days till the leave date . Can anyone suggest the approach and code if required .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2023 01:21 AM - edited ‎07-21-2023 01:32 AM
Hi @eshabartwal ,
You can use the Flow Designer for it and schedule it on a daily basis. Then your action would be to find the records where you limit the condition to more than 6 days and less than 8 days, so only the 7 days are in scope.
You can then setup your notification (you can use the record / data pill it is related to) directly in the Flow Designer or trigger an event and setup your notification the 'old' way via the notifications.
Something like (this specific condition is not tested😞
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2023 01:31 AM
Hello @eshabartwal
You need to create a Notification and Schedule Job.
Plz Mark my Solution as Accept and Give me thumbs up, if you find it Helpful.
Regards,
Samaksh
Plz Mark my Solution as Accept and Give me thumbs up, if you find it Helpful.
Regards,
Samaksh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2023 04:36 AM
Hello @eshabartwal ,
To implement a notification in ServiceNow that triggers 7 days prior to the leave end date and repeats daily until the leave date, you can follow these steps:
1. **Identify the Table and field name:**
2. **Create an Email Script Action:**
- Navigate to "System Notification" > "Email > Notification Email" in ServiceNow.
- Click on "New" to create a new email notification.
- Fill in the email details like the recipient, event, subject, sender, and message body.
- Save
3. **Create an Event for Sending Emails once an event gets triggered:**
- Navigate to "System Policy" > "Events" > "Event Registration" in ServiceNow.
- Click on "New" to create a new event registration.
- Set the "Event Name", "Table" and "Description" fields.
- Save
4. **Create a scheduled job to run daily and to trigger Event:**
- Go to Administration > System Configuration > Scheduled Jobs.
- Click New.
- Enter a name for the scheduled job, Run = Daily, and select the Time zone and time when you want the scheduled job to run.
- Write the script in the Script field. Please refer below script:
// #--------------------------Code to glide table and check if today falls in between the prior 7 days of Leave end date-----------------------------# //
var grIncident = new GlideRecord('incident');
//Kindly replace table and below query
grIncident.addEncodedQuery('u_leave_end_dateISNOTEMPTY');
grIncident.query();
// Loop through the matching records and process them
while (grIncident.next()) {
var leaveEndDate = "";
var incidentNumber = grIncident.getValue('number');
var leaveEndDate = grIncident.getValue('u_leave_end_date').toString();
var today = new GlideDate().toString();
// Create a GlideDate object for the current date
var currentDate = new GlideDate();
currentDate.setValue(leaveEndDate); // Set the value to "2023-07-28"
// Calculate the date 7 days in the past
var sevenDaysAgo = new GlideDate();
sevenDaysAgo.setValue(currentDate);
sevenDaysAgo.addDaysUTC(-7); // This subtracts 7 days
// Display the target date after subtracting 7 days
gs.info(sevenDaysAgo.toString() + " --- " + today); // Output: "2023-07-21"
if (sevenDaysAgo + "" === today + "") {
gs.eventQueue('<applicationScope.eventName>', grIncident, grIncident.caller_id.toString(), grIncident.sys_id);
gs.info('Incident Number: ' + incidentNumber + ', Leave End Date: ' + leaveEndDate);
}
}
-Save
The above code queries records from the 'incident' table in ServiceNow, retrieves the leave end date and then checks if the current date falls within the prior 7 days of each leave end date. If the condition is met, it triggers an event to send an email notification for the corresponding incident record.
for e.g. Leave end date = 2023-07-21
Then notification will be sent for 7 days between 2023-07-21 and 2023-07-14.
Note: if you want to send an email only on the prior 7th day i.e. in the above example only on 2023-07-14, then kindly replace the below "if condition".
if (sevenDaysAgo+"" == today) {
Let me know if you need any help!
If this helped you in any way, please hit the like button/mark it helpful. So it will help others to get the correct solution.
regards,
Prasad

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-27-2023 05:20 AM
Hi @eshabartwal ,
Did you get a chance to review my response?
Was my answer correct? Did you implement it?
So as to help others in the community, please mark my answer as correct and/or helpful.
Thanks,
Prasad