Otomasyon hızlı başlangıç kılavuzu

Google Dokümanlar belgesi oluşturan ve belgenin bağlantısını size e-postayla gönderen basit bir otomasyon oluşturup çalıştırın.

Hedefler

  • Komut dosyasını ayarlayın.
  • Komut dosyasını çalıştırın.

Ö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

Otomasyonu oluşturmak için aşağıdaki adımları uygulayın:

  1. Apps Komut Dosyası düzenleyiciyi açmak için script.google.com adresine gidin. İlk kez script.google.com adresine gidiyorsanız Kontrol panelini görüntüle'yi tıklayın.
  2. Yeni proje'yi tıklayın.
  3. Komut dosyası düzenleyicideki tüm kodları silip aşağıdaki kodu yapıştırın.

    templates/standalone/helloWorld.gs
    /**
     * Creates a Google Doc and sends an email to the current user with a link to the doc.
     */
    function createAndSendDocument() {
      try {
        // Create a new Google Doc named 'Hello, world!'
        const doc = DocumentApp.create('Hello, world!');
    
        // Access the body of the document, then add a paragraph.
        doc.getBody().appendParagraph('This document was created by Google Apps Script.');
    
        // Get the URL of the document.
        const url = doc.getUrl();
    
        // Get the email address of the active user - that's you.
        const email = Session.getActiveUser().getEmail();
    
        // Get the name of the document to use as an email subject line.
        const subject = doc.getName();
    
        // Append a new string to the "url" variable to use as an email body.
        const body = 'Link to your doc: ' + url;
    
        // Send yourself an email with a link to the document.
        GmailApp.sendEmail(email, subject, body);
      } catch (err) {
        // TODO (developer) - Handle exception
        console.log('Failed with error %s', err.message);
      }
    }
  4. Kaydet'i Kaydet simgesi tıklayın.

  5. Untitled project'i (Başlıksız proje) tıklayın.

  6. Senaryonuz için bir ad girin ve Yeniden adlandır'ı tıklayın.

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

Komut dosyasını çalıştırmak için aşağıdaki adımları uygulayın:

  1. Çalıştır'ı tıklayın.
  2. İ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.

  3. Komut dosyası yürütme işlemi tamamlandığında Gmail gelen kutunuzda e-posta olup olmadığını kontrol edin.

  4. E-postayı açın ve oluşturduğunuz dokümanı açmak için bağlantıyı tıklayın.

Sonraki adımlar