0

I have a script working fine however, I cannot work out how to add a popup reminder for after an all day event as started.... example: All day even is midnight to midnight, I want a notification at 9am that day.

my script uses event.addPopupReminder but this seems like it only works for before the event. When I manually look, you have the option to add a reminder "On the day at 9am" but how do I code this? using -900 within the code does not work

On the day at 9am

(I've snipped the code)

By default, if the cell is blank, it'll add a notification at 9am the day before, which I want to change to 9am on the day

   if (C2 == "") {C2 = '900'}
   event.addPopupReminder(C2)

On the spreadsheet, I've entered -900 (for 9am on the day) and -1000 (for 10am on the day), neither have worked.

Paul
  • 1
  • 2
  • Welcome to StackOverflow! Could you please provide more working code? And why did you try to pass ```-900``` as parameter, is it documented somewhere that's the way to setup "on the day at 9am" ? – Waxim Corp Jan 25 '23 at 12:34
  • HI Waxim, it's not documented anywhere to pass -900, it was a failed attempt as logically, I thought it might work given 900 returns 9am on the day before. What I cannot find on the forum boards is a time on the day, for all day events. Checking on Google, the parameter includes a note to say it's minutes before but there is no parameter for on the day despite having an option when manually editing a future all day event. I can only assume it's either a weird workaround or another parameter not listed https://developers.google.com/apps-script/reference/calendar/calendar-event-series – Paul Jan 25 '23 at 15:20
  • Did my suggestion answer your problem? – Waxim Corp Feb 01 '23 at 12:50

1 Answers1

0

The function you are asking doesn't exist, but there is a way to do it anyway. You just have to calcul the minutes between 9am and the start of your event manually.

You haven't put a lot of code, so I wrote something that probably need to be adapted to your case.

What the following function do :

  • Get all events of the day and for each :
  • Define the minutes between 9am and the start time
  • Add a reminder
function setReminderTodayEvents() {

  var today = new Date();
  today.setHours(9);
  today.setMinutes(0);
  today.setSeconds(0);

  var events = CalendarApp.getDefaultCalendar()
                          .getEventsForDay(today);

  for (var x = 0; x < events.length; x++) {
    var date_start = events[x].getStartTime();
    var delta = (date_start - today) / 1000 / 60; //ms to minute
    events[x].addPopupReminder(delta);
  }
}

Suggestion : add a trigger to execute that function every day between 7 and 8

References:

Waxim Corp
  • 657
  • 4
  • 16