create notifications with due date
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2023 01:03 PM
I need to send an email when the bill is 1 day past due, then 5 days later 7 etc, how do I do this by creating from 0, what are the steps to create notifications?
I already have a table with the due date field, I need to base it on
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2023 02:30 PM - edited 08-18-2023 02:33 PM
Hi @AndersonHenriqu,
1. Create event in even registry with name "event_name"
2. Create notification where Send when will be Event is fired and use above Event Name. And provide other details as per your requirement.This notification will trigger from scheduled job.
3. Create Schedule job which will run daily and send notification by triggering event
send1Days();
send5Days();
send7Days();
function send1Days(){
var gr = new GlideRecord('table');
gr.addEncodedQuery('due_dateBETWEENjavascript:gs.daysAgoStart(1)@javascript:gs.daysAgoEnd(1)');
gr.query();
while (gr.next()) {
gs.eventQueue("even_name", gr);//Use the event name created in point1
}
}
function send5Days(){
var gr = new GlideRecord('incident');
gr.addEncodedQuery('due_dateBETWEENjavascript:gs.daysAgoStart(5)@javascript:gs.daysAgoEnd(5)');
gr.query();
while (gr.next()) {
gs.eventQueue("even_name", gr); //Use the event name created in point1
}
}
function send7Days(){
var gr = new GlideRecord('incident');
gr.addEncodedQuery('due_dateBETWEENjavascript:gs.daysAgoStart(7)@javascript:gs.daysAgoEnd(7)');
gr.query();
while (gr.next()) {
gs.eventQueue("even_name", gr); ///Use the event name created in point1
}
}
}
Please Mark Answer correct if it helped.
Kumud
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2023 02:45 PM
Hello @AndersonHenriqu,
First, you need to create a scheduled job that runs periodically and queries the table with the due date field. The scheduled job should find the records that are past due by a certain number of days and trigger an event for each record. The event should pass the record itself and the assigned_to as parameters.
Second, you need to create a notification that listens for the event and sends an email to the recipient. The notification should have a condition that checks the number of days past due and matches it with the desired frequency of sending emails. For example, if you want to send an email 1 day past due, then 5 days later, then 7 days later, etc., you can use a condition like this:
gs.dateDiff (current.due_date, gs.nowDateTime (), true) == 1 || gs.dateDiff (current.due_date, gs.nowDateTime (), true) == 6 || gs.dateDiff (current.due_date, gs.nowDateTime (), true) == 13 || ...
The notification should also have a message template that contains the information you want to include in the email, such as the record number, due date, assigned_to, etc.
Third, you need to test your scheduled job and notification by creating some test records with different due dates and verifying that the emails are sent correctly.
If you need more details or examples, you can check out these web pages that I found for you:
- servicenow - trigger email one day before due date using javascript: This page shows how to create a scheduled job and an event for sending an email one day before the due date.
- Email notification if change task past due date on Service Now: This page shows how to fix some common errors when creating a scheduled job and an event.
- Email notification that triggers on a specific event in a different table: This page shows how to create a notification that listens for an event and sends an email.
I hope this helps
Kind Regards,
Swarnadeep Nandy
