Scheduled jobs to send emails between date ranges
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2024 03:33 PM - edited 03-12-2024 06:04 AM
Hi
I have a scheduled jobs in a scoped application which gets record from a table. The table has end date, reminder date, warning date all date fields.
The jobs needs to run everyday and
1. check if reminder date is greater than 30 then send a notification every 30 days until the warning date
2. check if reminder date is less than 30 then send a notification every 7 days until the warning date
in the code below today is the current date . This is what I have but its not triggering the monthly notice correctly and the weekly is triggering almost every day. What am I doing incorrectly?
while (gr.next()) {
var reminderDate = gr.getValue('reminder_date');
reminderDate = new GlideDateTime(reminderDate);
var warningdate= gr.getValue('warning_date');
warningdate= new GlideDateTime(warningdate);
var duration = GlideDateTime.subtract(today1, reminderDate);
var daysDifference = duration.getDayPart();
if (daysDifference > 0 && daysDifference % 30 === 0 && reminderDate <= warningdate) {
gs.eventQueue('monthly email', gr);
} else if (daysDifference < 30 && reminderDate <= warningdate) {
gs.eventQueue('weekly email', gr);
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2024 07:01 PM
Hi @gnewuser ,
Use encoded query instead of writing so many functions.
Write you script like :
var qrystr = "active=true^expiry_dateBETWEENjavascript:gs.now()@javascript:gs.daysAgo(-30)";
var expdt = new GlideRecord("table name");
expdt.addEncodedQuery(qrystr);
expdt.query();
while(expdt.next()){
gs.eventQueue('expiration.date',expdt,'','');//pass receipients in the parameter
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2024 06:08 AM
Thanks Sandeep for your response. So you are saying have only one event and pass the expiry date as the parameter for the event? But I need to compare it against warning date also.