Panduan memulai otomatisasi

Bangun dan jalankan otomatisasi sederhana yang membuat dokumen Google Dokumen dan mengirimi Anda link ke dokumen melalui email.

Tujuan

  • Menyiapkan skrip.
  • Jalankan skrip.

Prasyarat

Untuk menggunakan contoh ini, Anda memerlukan prasyarat berikut:

  • Akun Google (akun Google Workspace mungkin memerlukan persetujuan administrator).
  • Browser web dengan akses ke internet.

Menyiapkan skrip

Untuk membuat otomatisasi, lakukan langkah-langkah berikut:

  1. Untuk membuka editor Apps Script, buka script.google.com. Jika ini pertama kalinya Anda mengunjungi script.google.com, klik Lihat Dasbor.
  2. Klik Project baru.
  3. Hapus kode apa pun di editor skrip dan tempel kode di bawah.

    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. Klik Simpan Ikon simpan.

  5. Klik Project tanpa judul.

  6. Masukkan nama untuk skrip Anda, lalu klik Ganti nama.

Jalankan skrip:

Untuk menjalankan skrip, lakukan langkah-langkah berikut:

  1. Klik Run.
  2. Saat diminta, izinkan skrip. Jika layar izin OAuth menampilkan peringatan, Aplikasi ini tidak diverifikasi, lanjutkan dengan memilih Lanjutan > Buka {Project Name} (tidak aman).

  3. Setelah eksekusi skrip selesai, periksa email di kotak masuk Gmail Anda.

  4. Buka email dan klik tautan untuk membuka dokumen yang Anda buat.

Langkah berikutnya