מדריך למתחילים בנושא אוטומציה

ליצור ולהפעיל אוטומציה שיוצרת מסמך ב-Google Docs ושולחת לכם קישור למסמך באימייל.

מטרות

  • מגדירים את הסקריפט.
  • מריצים את הסקריפט.

דרישות מוקדמות

כדי להשתמש בדוגמה הזו, אתם צריכים לעמוד בדרישות המוקדמות הבאות:

  • חשבון Google (יכול להיות שחשבונות Google Workspace ידרשו אישור אדמין).
  • דפדפן אינטרנט עם גישה לאינטרנט.

הגדרת הסקריפט

כדי ליצור את הפעולות האוטומטיות, בצע את הפעולות הבאות:

  1. כדי לפתוח את הכלי לעריכת סקריפטים של Google Apps Script, עוברים אל script.google.com. אם זו הפעם הראשונה שאתם נכנסים ל-script.google.com, לוחצים על צפייה בלוח הבקרה.
  2. לוחצים על פרויקט חדש.
  3. מוחקים את הקוד בכלי לעריכת סקריפטים ומדביקים את הקוד הבא.

    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. לוחצים על שמירה סמל שמייצג את פעולת השמירה.

  5. לוחצים על פרויקט ללא שם.

  6. מזינים שם לסקריפט ולוחצים על שינוי השם.

הפעלת הסקריפט

כדי להריץ את הסקריפט:

  1. לוחצים על Run.
  2. כשמוצגת בקשה, מאשרים את הסקריפט. <<../samples/_snippets/oauth.md>>
  3. כשהסקריפט יסיים את ההרצה, צריך לבדוק את תיבת הדואר הנכנס ב-Gmail כדי למצוא את האימייל.
  4. פותחים את האימייל ולוחצים על הקישור כדי לפתוח את המסמך שיצרתם.

השלבים הבאים