Scheduled Job script to look at a Due Date and send a notification on Due date value?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-30-2019 09:49 AM
Hello team,
I have a requirement to trigger notification on daily basis based on due date field,
Acceptance Criteria:
Mail should trigger on the date of Due date and if due date hasn't changed it has to trigger the notification daily until the Due date changes to different value, if the due date changes it has to trigger notification again from that particular date until they change value to different value.
I'm new to Scheduled scripts no not sure how it works,any help would be appreciated.
Thanks,
Kuchi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-30-2019 12:03 PM
Lesson #1: Always wrap your scheduled scripts within a function. They execute in the same namespace with all other scheduled jobs and can cause conflicts.
Here is a quick run through of how the Run this script could look, we can plug the syntax in place once you're fine with the logic.
generate_email();
function generate_email() {
/* Query the table you want to check due date on. For example:
var gr = new GlideRecord("sc_task");
gr.addEncodedQuery("due_date<=javascript:gs.endOfToday()"); // At or before today
gr.query();
*/
/* Do something with your overdue stuff
while (gr.next()) {
gs.eventQueue("my_overdue_catalog_task_event", gr); // Queue event to send email
}
*/
}
What this would do is queue an event (which you tie to an email notification) for any catalog task that is due or overdue. The assumption I make is that when someone changes the due date, it's to a date in the future. Obviously if it's to a date in the past they still get the email daily.
In our world we would simply run this once a day. If you wanted it run more frequent then we can talk about different solutions.
Another more complicated solution is to queue events for the future but that's, from my experience, a more advanced solution. Most are simply OK with this sort of once a day summary.
Once you can get these questions answered and have the basics worked out we can also go through the big value add (I assume) - grouping all of a single user's overdue items together then providing them with a HTML formatted table of all of them with links to each individually. This prevents a single user from getting 5 overdue messages and makes them more likely to act on their overdue items (my experience).

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-30-2019 08:48 PM
Hi
When do you expect the notification to stop for any given record?
I understand, that you want to stop notifications, when the due date is changed to something in the future, but the more and more records you will have, the more notifications you will create on the long run.
Maybe you have to thing about a "closed" state, which prevents further notifications, even if the due date is passed.
Furthermore, you should collect all notifications that will be sent to the same user.
If I was the user and would receive a high number of notifications per day, that would be a bad user experience for me.
I recommend to send a daily report on the (over) due items, maybe ordered by the due date, meaning the ones being overdue for the longest time will be listed first.
On the report you can put one line per record being overdue, and with a column showing the due date.
Let me know if that answered your question and mark my answer as correct and helpful, please. Thanks
BR
Dirk