Home > Net >  Refer to columns in App Script in Google Sheets
Refer to columns in App Script in Google Sheets

Time:07-10

I am trying to refer to the information in each row to send multiple calendar invites based on event IDs (already generated).

Col A: Name

Col B: Email

Col C: Event Title

Col D: eventID

In my Script, I want to reference the columns of information but cannot figure out how to change my script (see below). All the events will be happening in the same Google Calendar so that ID will stay the same. I tried marking it as [2] and [4], [col 2], and [col D] but those did not work.

// Example 1: Add a guest to one event
function addAttendeeToEvent() {
  // Replace the below values with your own
  let attendeeEmail = [2]
  let calendarId = '[email protected]'
  let eventId = [4]

  let calendar = CalendarApp.getCalendarById(calendarId);
  if (calendar === null) {
    // Calendar not found
    console.log('Calendar not found', calendarId);
    return;
    }
  let event = calendar.getEventById(eventId);
  if (event === null) {
    // Event not found
    console.log('Event not found', eventId);
    return;
    }
  event.addGuest(attendeeEmail);
  }

CodePudding user response:

I think is where you wish to start from.

Presumably you can continue from here

function addAttendeeToEvent() {
  const ss = SpreadsheetApp.getActive();
  const sh = ss.getActiveSheet();
  const [h, ...vs] = sh.getDataRange().getValues();//assume one header row  
  let cal = CalendarApp.getCalendarById('[email protected]');
  if (cal) {
    vs.forEach((r, i) => {
      let ev = cal.getEventById(r[3]);
      if (ev) {
        ev.addGuest(r[1]);
      }
    })
  }
}
  • Related