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

สร้างและเรียกใช้การทำงานอัตโนมัติง่ายๆ ซึ่งจะสร้างเอกสาร 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 แสดงคำเตือน แอปนี้ยังไม่ได้รับการยืนยัน ให้ดำเนินการต่อโดยเลือกขั้นสูง > ไปที่ {ชื่อโปรเจ็กต์} (ไม่ปลอดภัย)

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

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

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