Multiple reminder notifications has been triggering through the schedule job

Abhilasha_123
Tera Contributor

Hi Team,

I have a requirement to create a reminder notification on the Approval table.

Conditions:

  • The approval state should be "Requested"
  • The approval record should have been created at least 24 hours earlier
  • The approver should receive the notification at 11 AM according to the user's timezone

To achieve this, I created a Scheduled Job that runs every hour and adjusts according to the user's timezone. However, users are receiving multiple reminder notifications, which should be avoided.

To prevent duplicate reminders, I added a custom field u_approval_reminder (Date/Time) to track when the last reminder was sent. I implemented the following logic to not send multiple reminders, but it’s not working as expected:

 

var sentRecently = false;

if (gr.u_approval_reminder) {

var lastSent = new GlideDateTime(gr.u_approval_reminder);

var diff = now.getNumericValue() - lastSent.getNumericValue();

// 24 hours in ms
if (diff < 86400000) {
sentRecently = true;
}
}

if (sentRecently) {
continue;

}
gr.u_approval_reminder = now;
gr.update();}

 
 
 
 
 
 
 
1 REPLY 1

pavani_paluri
Kilo Sage

Hi @Abhilasha_123 ,


Restrict to 11 AM only. Make sure the reminder logic only executes when the current time in the user’s timezone is exactly 11 AM. If it’s 10 AM or 12 PM, skip.

Check if a reminder was already sent today. Instead of comparing milliseconds (24 hours), compare the date. If the `u_approval_reminder` field already has today’s date, don’t send another reminder.

Update the reminder field immediately. As soon as you send the reminder, record today’s date/time in `u_approval_reminder`. That way, the next run will see it’s already done for today.

 

var now = new GlideDateTime();
var userTZ = gs.getUser().getTimeZoneName();
now.setTZ(userTZ);

// Only run at 11 AM
if (now.getHourOfDay() != 11) {
continue;
}

// Prevent duplicate reminders
var sentToday = false;
if (gr.u_approval_reminder) {
var lastSent = new GlideDateTime(gr.u_approval_reminder);
lastSent.setTZ(userTZ);

if (lastSent.getDate().equals(now.getDate())) {
sentToday = true;
}
}

if (sentToday) {
continue;
}

// Send reminder
// (notification logic here)

gr.u_approval_reminder = now;
gr.update();

 

Run the reminder logic only at 11 AM.
Before sending, ask: “Did I already send one today?”
If yes → skip.
If no → send and mark today’s date in the record.

This ensures each approver gets exactly one reminder per day at 11 AM, no matter how many times the job runs in that hour.

 

Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Pavani P