Change Notification

Johny1
Tera Expert

Notification Condition :-

IF - 

Planned end date is 5 business days past the current date - Trigger the notification

1 ACCEPTED SOLUTION

asifnoor
Kilo Patron

 

Hi,

You need to do this with the help of events and schedules.

1. Create an event (System policy -> Events -> Registry). Create new and select the table as change_request

2. Create a notification and under Send When, select "Event if Fired" and select the event name and then configure the notification as you want, under what it contains.

3. Then go to system Definition -> scheduled job and select "Automatically run a script of your choosing". Select daily under Run field. . and under script, place the below code.

This script will basically fetch all the change requests whose end_date is past 5 days of the current date and triggered the event. Once the event is triggered then the associated notification will get triggered.

var gr = new GlideRecord("change_request");
gr.addActiveQuery();
gr.addQuery("end_date",'!=','');
gr.query();
while(gr.next()) {
	var end_date = gr.getValue("end_date");
	var today_date = gs.daysAgo(5); //gets 5 days before Today.
	if(end_date <= today_date) {
          //It means that the end date is either 5 days form today or more than that. hence we need to send notification.  
	  gs.eventQueue('YOUR_EVENT_NAME', gr, gs.getUserID()); //replace the name here with the event name that you have created. 
	} 	
}

 

Mark the comment as a correct answer and also helpful once worked.

View solution in original post

2 REPLIES 2

asifnoor
Kilo Patron

 

Hi,

You need to do this with the help of events and schedules.

1. Create an event (System policy -> Events -> Registry). Create new and select the table as change_request

2. Create a notification and under Send When, select "Event if Fired" and select the event name and then configure the notification as you want, under what it contains.

3. Then go to system Definition -> scheduled job and select "Automatically run a script of your choosing". Select daily under Run field. . and under script, place the below code.

This script will basically fetch all the change requests whose end_date is past 5 days of the current date and triggered the event. Once the event is triggered then the associated notification will get triggered.

var gr = new GlideRecord("change_request");
gr.addActiveQuery();
gr.addQuery("end_date",'!=','');
gr.query();
while(gr.next()) {
	var end_date = gr.getValue("end_date");
	var today_date = gs.daysAgo(5); //gets 5 days before Today.
	if(end_date <= today_date) {
          //It means that the end date is either 5 days form today or more than that. hence we need to send notification.  
	  gs.eventQueue('YOUR_EVENT_NAME', gr, gs.getUserID()); //replace the name here with the event name that you have created. 
	} 	
}

 

Mark the comment as a correct answer and also helpful once worked.

Thank you Asifnoor.