I am still learning Apps Script. here is sample google sheet and the code for creating calendar events from the Google sheet's custom menu. I want to add delete events & calendar functions into the menu option.
But I am not able to get the event list by the to & from date. I took help from this link
function delete_events()
{
//Please note: Months are represented from 0-11 (January=0, February=1). Ensure dates are correct below before running the script.
var fromDate = new Date(); //This represents June 1st 2020
var toDate = new Date(); //This represents June 30th 2020
toDate.setHours(toDate.getHours()+24);
var calendarID = 'c_9ngacs4sflij848armjj9i91dk@group.calendar.google.com'; //Enter your calendar ID here
var calendar = CalendarApp.getCalendarById(calendarID);
Logger.log('calendar: '+calendar.getName());
//Search for events between fromdate and todate with given search criteria
var events = calendar.getEvents(fromDate, toDate);
Logger.log('Event: '+events.length);
// events.forEach(function(e,i){Logger.log(e[i])});
for(var i=0; i<events.length;i++) //loop through all events
{
var ev = events[i];
Logger.log('Event: '+ev.getTitle()+' found on '+ev.getStartTime()); // Log event name and title
ev.deleteEvent(); // delete event
}
}
My appscript.json file has following scopes added -
"oauthScopes": [
"https://www.googleapis.com/auth/calendar",
"https://www.googleapis.com/auth/script.external_request",
"https://www.googleapis.com/auth/spreadsheets.currentonly",
"https://www.googleapis.com/auth/spreadsheets"
],
But when I run the code above, I get following -
Then I see the actual calendar, which has full to events.
Why is that my function not working properly? Event id, CalId is Ok. So what is the cause of empty events?