מדריך למתחילים

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

מטרות

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

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

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

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

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

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

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

    תבניות/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. פותחים את הודעת האימייל ולוחצים על הקישור כדי לפתוח את המסמך שיצרתם.

השלבים הבאים