Note that there are some explanatory texts on larger screens.

plurals
  1. POCreate Google Calendar Events from Spreadsheet but prevent duplicates
    text
    copied!<p>I'm trying to write a script that will take data from a Google spreadsheet and create events in my Google calendar.</p> <p>I managed that fine but it produced duplicates every time I ran it. So now I'm trying to prevent that by creating a column 17 in the spreadsheet with an automatically produced unique event ID for each row and then each time the script is run it will look at the event ID for each row and delete the corresponding event in the calendar before recreating it with the original data or updated data if I've changed the row.</p> <p>I'm new to scripting of any kind and cobbled this together but am hitting a wall now. Can anyone help sort this out?</p> <pre><code>function CalInsert() { var cal = CalendarApp.getDefaultCalendar(); var id = SpreadsheetApp.getActiveSheet().getRange(2,17).getValue(); if (id != 0) { var event = cal.getEventSeriesById(id); event.deleteEventSeries(); } var sheet = SpreadsheetApp.getActiveSheet(); var startRow = 2; // First row of data to process var numRows = sheet.getLastRow(); // Number of rows to process var dataRange = sheet.getRange(startRow, 1, numRows, sheet.getLastColumn()); var data = dataRange.getValues(); for (i in data) { var row = data[i]; var title = row[0]; // First column var desc = row[13]; // Second column var tstart = row[14]; var tstop = row[15]; var event = cal.createEvent(title, tstart, tstop, {description:desc}); var eventid = event.getId(); SpreadsheetApp.getActiveSheet().getRange(2,17).setValue(eventid); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload