Send a notification when date is reached

umaaggarwal
Giga Guru
Giga Guru

I have a date field on incident form , I want to send a notification to assigned to person  when that date is reached.

1 ACCEPTED SOLUTION

asifnoor
Kilo Patron

Kindly refer to gs.eventQueueScheduled API which will help you to trigger the event at a required time. and you can configure the notification to listen to this event.

View solution in original post

3 REPLIES 3

Harsh Vardhan
Giga Patron

you can create here scheduled job and validate if the date field matched with current date then execute the gs.eventQueue() to trigger your event based notification. 

 

Create one Notification that will be trigger based on the event.

create on Event 

Create on Scheduled job and add the below script , try to modify the few of the field name in script based on your need. 

Sample Code:

var gr = new GlideRecord('incident');
	gr.addActiveQuery();
	gr.query();
	while(gr.next()){
		
		if(gr.<your date field Name> == gs.nowDateTime()){
			
			gs.eventQueue('<your event name>',gr,gr.assigned_to.toString());
		}
		
	}

 

Refer the below doc for further details about the notification. 

https://docs.servicenow.com/bundle/london-servicenow-platform/page/administer/notification/task/t_Cr...

 

 

Hi

 

Apologies for digging up an old thread but I am having some issues with the above script. I've amended it to try and get it to fire when the estimated_delivery field is not empty and less than the current time. However, it seems to be firing for every RITM in the system!!

My amended script is as follows:

var gr = new GlideRecord('sc_req_item');
	gr.addActiveQuery();
	gr.query();
	while(gr.next()){
		
		if(gr.estimated_delivery !== null || gr.estimated_delivery !== "" && (gr.estimated_delivery < gs.nowDateTime())){
			
			gs.eventQueue('missed_delivery',gr,gr.assigned_to.toString());
		}
		
	}

Can anyone point me to where I have gone wrong?!

 

TIA

asifnoor
Kilo Patron

Kindly refer to gs.eventQueueScheduled API which will help you to trigger the event at a required time. and you can configure the notification to listen to this event.