Send email notification when date is reached

riaz_mansuri
Kilo Guru

Hi,

I want an email to be sent when a specific date field has reached 30 days before the actual date.

I have set this on the contracts table but is it not working, does anyone know a script I can use?

find_real_file.png

The field is a date field called u_review_date

When this is less than 30 days away and email notification should be triggered.

Any ideas?

Thanks

1 ACCEPTED SOLUTION
23 REPLIES 23

mrswann
Kilo Guru

because that notification is only running once at the point of update, when the condition would be false...



I think you will need a scheduled job to fire an event, or potentially put a wait for activity within the workflow , to fire an event




The scheduled job would run each day and check for records which are "30 days", and use eventQueue() , you then use event registry to define the event, it will then be available to select from the notification "when an event is fired"


Hi,



Thanks ok, but any ideas on how I script this scheduled job?



I will try a workflow also



Thanks


var gr = new GlideRecord('task');


gr.addQuery('review_date', <=daysAgo(30));


gr.query();


while (gr.next()) {


eventQueue('youreventname-review_expired',gr.sys_id,gr.number,gr.short_description);


}




probably some bad syntax in here, and logical errors with the date


GlideSystem Date and Time Functions - ServiceNow Wiki


GlideRecord - ServiceNow Wiki  



set your job to run daily at around the time you want the emails fired, considering performance load


Chuck Tomasi
Tera Patron

Hi Riaz,



This could be a done a couple ways. If you are working on a task that uses a workflow, review the Timer activity before you trigger and event or send a notification (I prefer the former to the latter.)



Timer Activities - ServiceNow Wiki



If not, then a scheduled job would work well to query for records that have reached that date. A daily script works well, although you can run it more often (hourly) if you need. The script basically does a query for records with dates <= "now plus 30 days" and not already notified. That last part requires a secondary field such as a checkbox or date field (to note when the notification was sent) to avoid sending multiple notifications for the same record.



I did something very similar to this for my loaner request app (available on share) to remind people to pick up their loaner item, return their loaner item, and that their item is overdue for return.



Creating a Scheduled Job - ServiceNow Wiki


GlideRecord - ServiceNow Wiki