Krótkie wprowadzenie do automatyzacji

Utwórz i uruchom prostą automatyzację, która utworzy dokument Google i wyśle Ci e-maila z linkiem do niego.

Cele

  • Skonfiguruj skrypt.
  • Uruchom skrypt.

Wymagania wstępne

Aby użyć tego przykładu, musisz spełnić te wymagania wstępne:

  • Konto Google (w przypadku kont Google Workspace może być wymagana zgoda administratora).
  • przeglądarkę internetową z dostępem do internetu,

Konfigurowanie skryptu

Aby utworzyć automatyzację, wykonaj te czynności:

  1. Aby otworzyć edytor Apps Script, kliknij script.google.com. Jeśli odwiedzasz script.google.com po raz pierwszy, kliknij Wyświetl panel.
  2. Kliknij Nowy projekt.
  3. Usuń cały kod z edytora skryptów i wklej poniższy kod.

    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. Kliknij Zapisz Ikona zapisania.

  5. Kliknij Projekt bez nazwy.

  6. Wpisz nazwę skryptu i kliknij Zmień nazwę.

Uruchamianie skryptu

Aby uruchomić skrypt, wykonaj te czynności:

  1. Kliknij Wykonaj.
  2. Gdy pojawi się odpowiedni komunikat, autoryzuj skrypt. Jeśli na ekranie zgody OAuth wyświetla się ostrzeżenie Ta aplikacja nie została zweryfikowana, kliknij kolejno Zaawansowane > Otwórz {Project Name} (niebezpieczne).

  3. Po zakończeniu wykonywania skryptu sprawdź, czy w skrzynce odbiorczej Gmaila jest e-mail.

  4. Otwórz e-maila i kliknij link, aby otworzyć utworzony dokument.

Dalsze kroki