Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Google Apps Script: Add event to shared Google Calendar

first time asking something here! 🙂

So I wrote/copied a short script to add an event to my Google Calendar:

function createCalendarEvent() {
  var sheet = SpreadsheetApp.getActiveSheet();
  var calendar = CalendarApp.getCalendarById('FooBar');
 
  var startRow = 2;  // First row of data to process - 2 exempts my header row
  var numRows = sheet.getLastRow();   // Number of rows to process
  var numColumns = sheet.getLastColumn();
 
  var dataRange = sheet.getRange(startRow, 1, numRows-1, numColumns);
  var data = dataRange.getValues();
 
  var complete = "Done";
 
  for (var i = 0; i < data.length; ++i) {
    var row = data[i];
    Logger.log(row[0]);
    var name = row[0]; //Item Name
    var notes = row[3];  //Notes
    var startDate = new Date(row[1]);  //renewal date
    var endDate = new Date(row[2]); //remind date
    var eventID = row[6]; //event marked Done
   
    if (eventID != complete) {
      var currentCell = sheet.getRange(startRow + i, numColumns);
      calendar.createEvent(name, startDate, endDate, {
        description: notes
      });
    
      currentCell.setValue(complete);
    }
  }
}

This works great, but isn’t really the solution to my problem.
So straight to my question:
Is it posible to add events to someone elses calendar (maybe with ICAL?)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Also my Sheet looks like that:
Screenshot

>Solution :

If you have edit rights on the imported calendar then you can add a event to it. Just change the id (FooBar) to the right one. With this little script you output the calanders with some info to the console.

function readCalanders () {
  CalendarApp.getAllCalendars().forEach(cal => {
    console.log({
      name: cal.getName(), 
      id: cal.getId(),
      primary: cal.isMyPrimaryCalendar(),
      owendByMe: cal.isOwnedByMe()
      })
  })
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading