Bir konferanstaki oturumlar için kayıt oluşturun

Kodlama düzeyi: Başlangıç
Süre: 5 dakika
Proje türü: Özel menü ve etkinliğe dayalı tetikleyici ile otomasyon

Hedefler

  • Çözümün ne işe yaradığını anlayın.
  • Apps Komut Dosyası hizmetlerinin çözümdeki işlevlerini anlama.
  • Komut dosyasını ayarlayın.
  • Komut dosyasını çalıştırın.

Bu çözüm hakkında

Uçtan uca etkinlik kaydı sistemi oluşturun. Yaklaşan bir etkinliğiniz (ör. konferans) varsa konferans oturumları için yeni bir takvim oluşturabilir, kayıt formu oluşturabilir ve katılımcılara otomatik olarak kişiselleştirilmiş etkinlik programları gönderebilirsiniz.

E-Tablolar'daki bilgilerin Formlar'a ve Takvim'e aktarılması

İşleyiş şekli

Bu çözüm, otomatik bir etkinlik kayıt sistemi uygulamak için Google E-Tablolar'da özel bir menü kullanır. Komut dosyası, E-Tablolar'daki konferans etkinliklerinin listelendiği bir takvim oluşturur. Ardından, katılımcıların kaydolabileceği etkinliklerin listesini içeren bir form oluşturur. Katılımcılar formu doldurduktan sonra komut dosyası, katılımcıları takvim etkinliklerine ekler ve onlara gezi planlarını e-postayla gönderir.

Apps Komut Dosyası hizmetleri

Bu çözümde aşağıdaki hizmetler kullanılır:

  • E-tablo hizmeti: Etkinlik bilgilerini diğer hizmetlere sağlar.
  • Takvim hizmeti: Etkinlik için yeni bir takvim oluşturur, takvime etkinlik ekler ve katılımcıları kaydoldukları etkinliklere ekler.
  • Properties service: Takvim hizmeti tarafından oluşturulan takvimin kimliğini depolar. Bir kullanıcı, özel Konferans menüsünden Konferans oluştur'u tıkladığında, Özellikler hizmeti, takvim kimliği özelliğinin mevcut olup olmadığını kontrol ederek etkinlik kayıt sisteminin daha önce ayarlanıp ayarlanmadığını kontrol eder. Bu işlem, yinelenen form ve takvimlerin oluşturulmasını önlemeye yardımcı olur.
  • Formlar hizmeti: E-tablodaki bilgilerden, katılımcıların oturumlara kaydolmasına olanak tanıyan bir form oluşturur.
  • Komut dosyası hizmeti: Katılımcı formu doldurduğunda tetiklenen bir tetikleyici oluşturur.
  • Doküman hizmeti: Bir katılımcının kaydolduğu etkinliklerle ilgili etkinlik bilgilerini alır ve etkinliklerin listesini yeni bir dokümana ekler. Komut dosyası, katılımcıya belgeyi düzenleme izni verir.
  • Posta hizmeti: Etkinlik programı dokümanını katılımcıya e-postayla gönderir.

Ön koşullar

Bu örneği kullanmak için aşağıdaki ön koşulları karşılamanız gerekir:

  • Google Hesabı (Google Workspace hesapları için yönetici onayı gerekebilir).
  • İnternete erişimi olan bir web tarayıcısı.

Komut dosyasını ayarlama

  1. Create a sign-up for sessions at a conference örnek e-tablosunun kopyasını oluşturmak için aşağıdaki düğmeyi tıklayın. Bu çözümün Apps Komut Dosyası projesi, e-tabloya eklenir.
    Kopya oluştur
  2. Konferans > Konferans ayarlama'yı tıklayın. Bu özel menünün görünmesi için sayfayı yenilemeniz gerekebilir.
  3. İstendiğinde komut dosyasını yetkilendirin. OAuth kullanıcı rızası ekranında Bu uygulama doğrulanmadı uyarısı gösteriliyorsa Gelişmiş > {Proje Adı} adlı projeye git (güvenli değil)'i seçerek devam edin.

  4. Konferans > Konferansı tekrar ayarla'yı tıklayın.

Komut dosyasını çalıştırma

  1. Araçlar > Formu Yönet > Canlı forma git'i tıklayın.
  2. Formu doldurup gönderin.
  3. calendar.google.com adresine gidin.
  4. Sol tarafta, Konferans Takvimi'nin yanındaki kutunun işaretli olduğundan emin olun.
  5. Kaydolduğunuz etkinliklerin tarihlerine gidin ve katılımcı olarak eklendiğinizi onaylayın.

(İsteğe bağlı) Çözümü sıfırlama

Bu çözümü tekrar denemek veya kendi etkinlik bilgilerinizi kullanacak şekilde özelleştirmek istiyorsanız komut dosyasını ilk çalıştırdığınızda ayarlanan bazı öğeleri sıfırlamanız gerekir. Çözümü sıfırlama adımlarını görüntülemek için aşağıdaki Çözümü sıfırla'yı tıklayın:

Çözümü sıfırlama

1. adım: Kayıtlı komut dosyası özelliklerini sıfırlayın

Komut dosyasını birden fazla kez çalıştırmaya çalışırsanız Konferansınız zaten ayarlandı. Kayıt formunuzu Google Drive'da bulun. Bunun nedeni, konferans takvimi oluşturulduktan sonra takvim kimliğinin komut dosyası özelliği olarak depolanmasıdır. Komut dosyası çalıştırıldığında takvim kimliği özelliğinin mevcut olup olmadığını kontrol eder ve mevcutsa çalışmayı durdurur.

Mevcut takvim kimliği özelliğini kaldırmak için aşağıdaki adımları uygulayın:

  1. E-tabloda Uzantılar > Apps Komut Dosyası'nı tıklayın.
  2. Apps Komut Dosyası Düzenleyici'de, işlev açılır listesinden resetProperties simgesini seçin ve Çalıştır'ı tıklayın.

2. adım: Konferans Takvimi'ni silin

Komut dosyası her çalıştırıldığında yeni bir takvim oluşturulur. Oluşturulan orijinal takvimi saklamak istemiyorsanız aşağıdaki adımları uygulayın:

  1. calendar.google.com adresine gidin.
  2. Konferans Takvimi'nin yanındaki Konferans Takvimi Seçenekleri'ni > Ayarlar ve paylaşım'ı tıklayın.
  3. Ayarların en altına gidip Sil'i tıklayın.

3. adım: Form gönderme tetikleyicisini silin

Komut dosyası, her çalıştırıldığında form gönderimleri için bir tetikleyici oluşturur. Yinelenen e-postalara neden olan birden fazla tetikleyiciyi önlemek için orijinal tetikleyiciyi kaldırın. Şu adımları uygulayın:

  1. E-tabloda Uzantılar > Apps Komut Dosyası'nı tıklayın.
  2. Apps Komut Dosyası projesinde, sol tarafta Tetikleyiciler'i tıklayın.
  3. Tetikleyicinin yanındaki Diğer > Tetikleyiciyi sil'i tıklayın.

Komut dosyasını her çalıştırdığınızda yeni bir form oluşturulur. Formun e-tablonuzla bağlantısını kaldırıp formu silmek için aşağıdaki adımları uygulayın:

  1. E-tabloda, Form yanıtları sayfasını sağ tıklayın ve Formun bağlantısını kaldır > Tamam'ı tıklayın.
  2. Form yanıtları sayfasını tekrar sağ tıklayın ve Sil > Tamam'ı tıklayın.
  3. forms.google.com adresine gidin.
  4. Konferans Formu'nu sağ tıklayın ve Kaldır > Çöp kutusuna taşı'yı tıklayın.

Çözümü sıfırladıktan sonra kendi verilerinizi ekleyebilir veya örnek verileri kullanmaya devam edip komut dosyasını tekrar çalıştırabilirsiniz.

Kodu inceleme

Bu çözümün Apps Komut Dosyası kodunu incelemek için aşağıdaki Kaynak kodu görüntüle'yi tıklayın:

Kaynak kodu göster

Code.gs

solutions/automations/event-session-signup/Code.js
// To learn how to use this script, refer to the documentation:
// https://developers.google.com/apps-script/samples/automations/event-session-signup

/*
Copyright 2022 Google LLC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

/**
 * Inserts a custom menu when the spreadsheet opens.
 */
function onOpen() {
  SpreadsheetApp.getUi().createMenu('Conference')
      .addItem('Set up conference', 'setUpConference_')
      .addToUi();
}

/**
 * Uses the conference data in the spreadsheet to create
 * Google Calendar events, a Google Form, and a trigger that allows the script
 * to react to form responses.
 */
function setUpConference_() {
  let scriptProperties = PropertiesService.getScriptProperties();
  if (scriptProperties.getProperty('calId')) {
    Browser.msgBox('Your conference is already set up. Look in Google Drive for your'
                   + ' sign-up form!');
                   return;
  }
  let ss = SpreadsheetApp.getActive();
  let sheet = ss.getSheetByName('Conference Setup');
  let range = sheet.getDataRange();
  let values = range.getValues();
  setUpCalendar_(values, range);
  setUpForm_(ss, values);
  ScriptApp.newTrigger('onFormSubmit').forSpreadsheet(ss).onFormSubmit()
      .create();
}

/**
 * Creates a Google Calendar with events for each conference session in the
 * spreadsheet, then writes the event IDs to the spreadsheet for future use.
 * @param {Array<string[]>} values Cell values for the spreadsheet range.
 * @param {Range} range A spreadsheet range that contains conference data.
 */
function setUpCalendar_(values, range) {
  let cal = CalendarApp.createCalendar('Conference Calendar');
  // Start at 1 to skip the header row.
  for (let i = 1; i < values.length; i++) {
    let session = values[i];
    let title = session[0];
    let start = joinDateAndTime_(session[1], session[2]);
    let end = joinDateAndTime_(session[1], session[3]);
    let options = {location: session[4], sendInvites: true};
    let event = cal.createEvent(title, start, end, options)
        .setGuestsCanSeeGuests(false);
    session[5] = event.getId();
  }
  range.setValues(values);

  // Stores the ID for the Calendar, which is needed to retrieve events by ID.
  let scriptProperties = PropertiesService.getScriptProperties();
  scriptProperties.setProperty('calId', cal.getId());
}

/**
 * Creates a single Date object from separate date and time cells.
 *
 * @param {Date} date A Date object from which to extract the date.
 * @param {Date} time A Date object from which to extract the time.
 * @return {Date} A Date object representing the combined date and time.
 */
function joinDateAndTime_(date, time) {
  date = new Date(date);
  date.setHours(time.getHours());
  date.setMinutes(time.getMinutes());
  return date;
}

/**
 * Creates a Google Form that allows respondents to select which conference
 * sessions they would like to attend, grouped by date and start time in the
 * caller's time zone.
 *
 * @param {Spreadsheet} ss The spreadsheet that contains the conference data.
 * @param {Array<String[]>} values Cell values for the spreadsheet range.
 */
function setUpForm_(ss, values) {
  // Group the sessions by date and time so that they can be passed to the form.
  let schedule = {};
  // Start at 1 to skip the header row.
  for (let i = 1; i < values.length; i++) {
    let session = values[i];
    let day = session[1].toLocaleDateString();
    let time = session[2].toLocaleTimeString();
    if (!schedule[day]) {
      schedule[day] = {};
    }
    if (!schedule[day][time]) {
      schedule[day][time] = [];
    }
    schedule[day][time].push(session[0]);
  }

  // Creates the form and adds a multiple-choice question for each timeslot.
  let form = FormApp.create('Conference Form');
  form.setDestination(FormApp.DestinationType.SPREADSHEET, ss.getId());
  form.addTextItem().setTitle('Name').setRequired(true);
  form.addTextItem().setTitle('Email').setRequired(true);
  Object.keys(schedule).forEach(function(day) {
    let header = form.addSectionHeaderItem().setTitle('Sessions for ' + day);
    Object.keys(schedule[day]).forEach(function(time) {
      let item = form.addMultipleChoiceItem().setTitle(time + ' ' + day)
          .setChoiceValues(schedule[day][time]);
    });
  });
}

/**
 * Sends out calendar invitations and a
 * personalized Google Docs itinerary after a user responds to the form.
 *
 * @param {Object} e The event parameter for form submission to a spreadsheet;
 *     see https://developers.google.com/apps-script/understanding_events
 */
function onFormSubmit(e) {
  let user = {name: e.namedValues['Name'][0], email: e.namedValues['Email'][0]};

  // Grab the session data again so that we can match it to the user's choices.
  let response = [];
  let values = SpreadsheetApp.getActive().getSheetByName('Conference Setup')
      .getDataRange().getValues();
  for (let i = 1; i < values.length; i++) {
    let session = values[i];
    let title = session[0];
    let day = session[1].toLocaleDateString();
    let time = session[2].toLocaleTimeString();
    let timeslot = time + ' ' + day;

    // For every selection in the response, find the matching timeslot and title
    // in the spreadsheet and add the session data to the response array.
    if (e.namedValues[timeslot] && e.namedValues[timeslot] == title) {
      response.push(session);
    }
  }
  sendInvites_(user, response);
  sendDoc_(user, response);
}

/**
 * Add the user as a guest for every session he or she selected.
 * @param {object} user An object that contains the user's name and email.
 * @param {Array<String[]>} response An array of data for the user's session choices.
 */
function sendInvites_(user, response) {
  let id = ScriptProperties.getProperty('calId');
  let cal = CalendarApp.getCalendarById(id);
  for (let i = 0; i < response.length; i++) {
    cal.getEventSeriesById(response[i][5]).addGuest(user.email);
  }
}

/**
 * Creates and shares a personalized Google Doc that shows the user's itinerary.
 * @param {object} user An object that contains the user's name and email.
 * @param {Array<string[]>} response An array of data for the user's session choices.
 */
function sendDoc_(user, response) {
  let doc = DocumentApp.create('Conference Itinerary for ' + user.name)
      .addEditor(user.email);
  let body = doc.getBody();
  let table = [['Session', 'Date', 'Time', 'Location']];
  for (let i = 0; i < response.length; i++) {
    table.push([response[i][0], response[i][1].toLocaleDateString(),
      response[i][2].toLocaleTimeString(), response[i][4]]);
  }
  body.insertParagraph(0, doc.getName())
      .setHeading(DocumentApp.ParagraphHeading.HEADING1);
  table = body.appendTable(table);
  table.getRow(0).editAsText().setBold(true);
  doc.saveAndClose();

  // Emails a link to the Doc as well as a PDF copy.
  MailApp.sendEmail({
    to: user.email,
    subject: doc.getName(),
    body: 'Thanks for registering! Here\'s your itinerary: ' + doc.getUrl(),
    attachments: doc.getAs(MimeType.PDF),
  });
}

/**
 * Removes the calId script property so that the 'setUpConference_()' can be run again.
 */
function resetProperties(){
  let scriptProperties = PropertiesService.getScriptProperties();
  scriptProperties.deleteAllProperties();
}

Katkıda bulunanlar

Bu örnek, Google Geliştirici Uzmanları'nın yardımıyla Google tarafından yönetilir.

Sonraki adımlar