- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2016 01:38 PM
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?
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
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-29-2016 06:12 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2016 01:41 PM
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"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2016 01:47 PM
Hi,
Thanks ok, but any ideas on how I script this scheduled job?
I will try a workflow also
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2016 01:57 PM
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
set your job to run daily at around the time you want the emails fired, considering performance load

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2016 01:51 PM
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