Quantcast
Channel: Hot Weekly Questions - Web Applications Stack Exchange
Viewing all articles
Browse latest Browse all 9782

Trigger script to share calender with new user whenever form updates sheet with a new email address

$
0
0

I have a Google form that allows people to submit their name and email address in order to sign up for a private shared calendar.

The form populates a Google sheet.

I want to automatically add new email addresses from the sheet to the Google calendar.

Based on guidance online, I added the following script via the Extensions menu and then Apps Script. It doesn't produce any errors BUT also doesn't seem to work. I'm new to this type of development, so any guidance is welcome.

function onEdit(e) {  // If the event object is not provided (e.g., when triggered by an installable trigger)  if (!e || !e.source) {    // Provide a default sheet and range for testing (modify as needed)    var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();    var range = sheet.getActiveRange();  } else {    // Use the event object properties if available    var sheet = e.source.getSheetByName('Form Responses 1');     var range = e.range;  }  // Check if the edited cell is in a specific range (Column C, starting from the last row)  if (range.getColumn() === 3 && range.getRow() === sheet.getLastRow()) {    var emailAddress = range.getValue();    // Call the function to share the calendar with the email address    shareCalendarWithEmail(emailAddress);  }}function shareCalendarWithEmail(emailAddress) {  var calendarId = 'mycalendarid@group.calendar.google.com';  // Get the Calendar API  var calendar = CalendarApp.getCalendarById(calendarId);  // Get the calendar's access control list (ACL)  var calendarAcl = Calendar.Acl.list(calendarId);  // Create a new calendar rule to provide read access to the specified email address  var newRule = {    role: 'reader',    scope: {      type: 'user',      value: emailAddress,    },  };  // Insert the new rule into the calendar's ACL  Calendar.Acl.insert(calendarId, newRule);  // Log the success message if needed  Logger.log('Calendar shared with: '+ emailAddress);}

Viewing all articles
Browse latest Browse all 9782

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>