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

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

מטרות

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

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

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

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

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

כדי ליצור את האוטומציה:

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

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

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

השלבים הבאים