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

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

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

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

השלבים הבאים