Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

create notifications with due date

AndersonHenriqu
Tera Contributor
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

 

2 REPLIES 2

Kumud Ranjan
Mega Guru

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

SwarnadeepNandy
Mega Sage

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:

I hope this helps

 

Kind Regards,

Swarnadeep Nandy