Retrieving the Hangouts link after creating the event and designating an attendee as a co-organizer in apps script for an event

I’m developing an automation script using Google Apps Script to streamline the process of creating events in Google Calendar from data stored in a Google Sheets spreadsheet. My problems here are:
Retrieving the Hangouts link after creating the event: I need assistance with retrieving the Hangouts link associated with a calendar event immediately after creating it through Apps Script. This link is essential for integrating video conferencing functionality into the events.
Designating an attendee as a co-organizer: I would also like to designate one of the attendees as a co-organizer of the event. However, I’m unsure about the specific method or property to use in Google Apps Script to achieve this.

function crearEvento() {
  let ultimaCelda = encontrarUltFila();

  // Recorrer las filas con datos en la hoja "Calendar"
  for (let fila = 3; fila <= ultimaCelda; fila++) {
    const nombreEvento = hojaCalendario.getRange("B" + fila).getValue();
    const fechaInicio = hojaCalendario.getRange("C" + fila).getValue();
    const fechaFin = hojaCalendario.getRange("D" + fila).getValue();
    const coanfitrion = hojaCalendario.getRange("E" + fila).getValue();    
    const calendarID = hojaCalendario.getRange("F" + fila).getValue();
    const valorDia = hojaTecnicas.getRange('I' + fila).getValue();
    
    const calendar = CalendarApp.getCalendarById(calendarID);

    try {
      const options = {
        guests: coanfitrion,
        sendInvites: false,
        conferenceDataVersion: 1
      };

      // Verificar si valorDia es un día válido y construir la recurrencia
      let recurrence;
      switch (valorDia) {
        case "Lunes":
          recurrence =                   CalendarApp.newRecurrence().addWeeklyRule().onlyOnWeekday(CalendarApp.Weekday.MONDAY);
          break;
        case "Martes":
          recurrence = CalendarApp.newRecurrence().addWeeklyRule().onlyOnWeekday(CalendarApp.Weekday.TUESDAY);
          break;
        case "Miercoles":
          recurrence = CalendarApp.newRecurrence().addWeeklyRule().onlyOnWeekday(CalendarApp.Weekday.WEDNESDAY);
          break;
        case "Jueves":
          recurrence = CalendarApp.newRecurrence().addWeeklyRule().onlyOnWeekday(CalendarApp.Weekday.THURSDAY);
          break;
        case "Viernes":
          recurrence = CalendarApp.newRecurrence().addWeeklyRule().onlyOnWeekday(CalendarApp.Weekday.FRIDAY);
          break;
        case "Sabado":
          recurrence = CalendarApp.newRecurrence().addWeeklyRule().onlyOnWeekday(CalendarApp.Weekday.SATURDAY);
          break;
        default:
          console.log("Día no válido:", valorDia);
          continue; // Saltar a la siguiente iteración del bucle
      }

      const fechaFinalizacion = new Date("2024-7-31");
      recurrence.until(fechaFinalizacion);

      // Crear el evento con o sin recurrencia
      if (recurrence) {
        const eventSeries = calendar.createEventSeries(nombreEvento, new Date(fechaInicio), new Date(fechaFin), recurrence, options);
        const eventSeriesId = eventSeries.getId();
        hojaCalendario.getRange("G" + fila).setValue(eventSeriesId);
        
        console.log('Evento recurrente creado:', nombreEvento, 'Fecha de inicio:', fechaInicio, 'Fecha de fin:', fechaFin, 'Día de la semana:', valorDia);
      } else {
        const event = calendar.createEvent(nombreEvento, new Date(fechaInicio), new Date(fechaFin), options);
        const eventoId = event.getId();
        hojaCalendario.getRange("G" + fila).setValue(eventoId);
        
        console.log('Evento creado:', nombreEvento, 'Fecha de inicio:', fechaInicio, 'Fecha de fin:', fechaFin, 'Día de la semana:', valorDia);
      }
    } catch (error) {
      console.error('Error al crear el evento:', error);
    }
  }
}

function modificarEventos(){
  let ultimaCelda = encontrarUltFila();
  
  // Recorrer las filas con datos en la hoja "Calendar"
  for (let fila = 3; fila <= ultimaCelda; fila++) {
    const colorF = hojaTecnicas.getRange("F" + fila).getValue();
    const calendarID = hojaCalendario.getRange("F" + fila).getValue();
    const eventId = hojaCalendario.getRange("G" + fila).getValue(); // Obtener el ID del evento
  
    try {
      // Retrieve the event object using calendar ID and event ID
      const event = CalendarApp.getCalendarById(calendarID).getEventById(eventId);

      if (event) {
        // Determinar color según el valor de la columna F
        let color;
        switch(colorF) {
          case "FI":
            color = CalendarApp.EventColor.PALE_BLUE; // Pavo real
            break;
          case "FH":
            color = CalendarApp.EventColor.PALE_RED; // Flamenco
            break;
          case "FJSyC":
            color = CalendarApp.EventColor.GREEN; // Salvia
            break;
          case "FAE":
            color = CalendarApp.EventColor.YELLOW; // Banana
            break;
          default:
            color = null; // Sin color específico
        }
          
        event.setColor(color);
        event.setGuestsCanInviteOthers(false)
        event.setGuestsCanSeeGuests(true)
        event.setGuestsCanModify(false)        
      } else {
        // Log a message if the event is not found
        console.log('Event not found for calendar ID:', calendarID, 'and event ID:', eventId);
      }
    } catch (error) {
      // Handle potential errors during event modification
      console.error('Error modifying event:', error);
    }
  }
}

function encontrarUltFila(){
  var ultimaFila = hojaCalendario.getLastRow();
  var valoresColumnaF = hojaCalendario.getRange('B1:B' + ultimaFila).getValues();
  
  for (var i = ultimaFila; i > 0; i--) {
    if (valoresColumnaF[i - 1][0] != "") {
      var ultimaCelda = i;
      Logger.log("La última celda con valor en la columna B es: " + ultimaCelda);
      break;
    }
  }
  
  return ultimaCelda;
}

New contributor

Luca Invernizzi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật