Creating Multiple Full-Day Events on Same Date in Google Calendar

I’m working on a Google Apps Script that reads data from a spreadsheet and creates calendar events. The script works fine for adding one event per day or updating existing ones, but I can’t figure out how to add multiple all-day events on the same date.

Here’s my current code:

function syncCalendarEvents(){
  var calendar = CalendarApp.getCalendarById("MyCalendarID");
  var sheet = SpreadsheetApp.getActive().getSheetByName("Data");
  const allRows = sheet.getDataRange().getValues();
  allRows.forEach(function(currentRow, rowIndex){
    if (rowIndex === 0) return;
    var scheduleDate = sheet.getRange(rowIndex, 4, 1, 1).getValue();
    var eventName = sheet.getRange(rowIndex,1,1,1).getValue();
    var eventDetails = sheet.getRange(rowIndex,2,1,1).getValue();
    console.log(scheduleDate + eventName + eventDetails)
    const targetDate = new Date(scheduleDate)
    const existingEvents = calendar.getEventsForDay(targetDate);
    if (existingEvents.length == 0){
      calendar.createAllDayEvent(eventName,targetDate,{description: eventDetails});
    } else {
      selectedEvent = existingEvents[0];
      selectedEvent.setDescription(eventDetails)
    }
  })
}

The problem is when I try to add a second employee’s status for the same day, it just updates the first event instead of creating a new one. I think the issue is with checking existingEvents.length == 0 but I’m not sure how to modify it to allow multiple events per day.

I need this for tracking employee attendance where multiple people might be absent or late on the same day. Each person should get their own calendar event. Any suggestions on how to fix this logic?

You’re manually coding event management when you should automate this whole workflow.

I’ve built similar employee tracking systems and wasted tons of time debugging Google Apps Script issues. Your approach works but you’ll hit rate limits, deal with auth problems, and spend hours maintaining custom code.

Skip the scripts - set up automation that handles everything. Trigger new calendar events when spreadsheet data changes, auto-check for duplicates by employee name, send notifications.

Switched our team’s attendance tracking to this last year. Someone updates the spreadsheet, everything happens automatically. No more manual script runs or debugging.

The automation reads spreadsheet changes in real time, checks existing calendar events by title match, creates new events only when needed. You get error handling and retry logic built in.

Your logic’s close but you’ll save massive headaches automating instead of managing custom code.

Your script’s broken because it assumes max one event per day. When you check existingEvents.length == 0, any existing event blocks new ones - doesn’t matter which employee.

I hit this same issue building a vacation tracker for multiple departments. You need to check if your specific employee already has an event, not whether any events exist.

Ditch that condition and search existing events for a match instead. Loop through existingEvents and compare titles against your eventName. No match? Create the event. Match found? Update that one.

const existingEvents = calendar.getEventsForDay(targetDate);
let foundMatch = false;
for (let event of existingEvents) {
  if (event.getTitle() === eventName) {
    event.setDescription(eventDetails);
    foundMatch = true;
    break;
  }
}
if (!foundMatch) {
  calendar.createAllDayEvent(eventName, targetDate, {description: eventDetails});
}

Now each employee gets their own event and updates only hit the right person’s entry.

You’re checking if ANY events exist that day, not if an event for that specific employee exists.

I hit this same problem building an office scheduling system. You need to filter existing events by title or description to see if that employee already has an event.

Here’s how I’d fix it:

const existingEvents = calendar.getEventsForDay(targetDate);
const matchingEvent = existingEvents.find(event => event.getTitle() === eventName);

if (!matchingEvent) {
  calendar.createAllDayEvent(eventName, targetDate, {description: eventDetails});
} else {
  matchingEvent.setDescription(eventDetails);
}

This only updates if there’s already an event with the same title (employee name). Otherwise it creates a new one.

You could also check by description content or store employee IDs in the description and parse that. But matching by title works fine for most cases.

Been using this approach for years - handles multiple events per day without issues.

Your condition logic is the problem - it treats any event on a date as blocking new ones. So when employee A has an event and you try adding employee B, the script finds existing events and just updates the first one.

I hit this same issue tracking project deadlines with multiple team members on the same day. You need to check for specific event matches, not just count total events.

Right now you’re grabbing all events for the day and checking if any exist. Instead, search through existing events to see if one matches your current employee’s event name. Only create new events when there’s no match for that specific employee.

You could store unique IDs in event descriptions and parse those, but that’s overkill. Matching by event title works better and keeps things simple for employee attendance.