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

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

מטרות

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

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

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

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

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

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

  1. כדי לפתוח את עורך Apps Script, נכנסים לכתובת script.google.com. אם זו הפעם הראשונה שאתם נכנסים אל script.google.com, לוחצים על View Dashboard.
  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. כשמוצגת בקשה, מאשרים את הסקריפט. אם במסך ההסכמה של OAuth מוצגת האזהרה האפליקציה הזו לא מאומתת, ממשיכים בלחיצה על מתקדם > מעבר אל {Project Name} (לא בטוח).

  3. כשהרצת הסקריפט תסתיים, חפשו את האימייל בתיבת הדואר הנכנס של Gmail.

  4. פותחים את הודעת האימייל ולוחצים על הקישור כדי לפתוח את המסמך שיצרתם.

השלבים הבאים