การเริ่มต้นใช้งานการทำงานอัตโนมัติอย่างรวดเร็ว

สร้างและเรียกใช้การทำงานอัตโนมัติง่ายๆ ซึ่งจะสร้างเอกสาร Google เอกสารและส่งอีเมลพร้อมลิงก์ไปยังเอกสารให้คุณ

วัตถุประสงค์

  • ตั้งค่าสคริปต์
  • เรียกใช้สคริปต์

ข้อกำหนดเบื้องต้น

หากต้องการใช้ตัวอย่างนี้ คุณต้องมีข้อกำหนดเบื้องต้นต่อไปนี้

  • บัญชี 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. คลิกเรียกใช้
  2. เมื่อได้รับข้อความแจ้ง ให้ให้สิทธิ์สคริปต์ หากหน้าจอความยินยอมของ OAuth แสดงคำเตือน แอปนี้ไม่ได้รับการยืนยัน ให้ดำเนินการต่อโดยเลือกขั้นสูง > ไปที่ {Project Name} (ไม่ปลอดภัย)

  3. เมื่อการทำงานของสคริปต์เสร็จสมบูรณ์ ให้ตรวจสอบอีเมลในกล่องจดหมาย Gmail

  4. เปิดอีเมลและคลิกลิงก์เพื่อเปิดเอกสารที่คุณสร้าง

ขั้นตอนถัดไป