คู่มือเริ่มต้นการทํางานอัตโนมัติฉบับย่อ

จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ

สร้างและเรียกใช้การทํางานอัตโนมัติที่สร้างเอกสาร Google เอกสาร และส่งลิงก์เอกสารให้คุณทางอีเมล

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

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

สิ่งที่ต้องดำเนินการก่อน

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

  • บัญชี Google (บัญชี Google Workspace อาจต้องได้รับการอนุมัติจากผู้ดูแลระบบ)
  • เว็บเบราว์เซอร์ที่เข้าถึงอินเทอร์เน็ตได้

ตั้งค่าสคริปต์

หากต้องการสร้างระบบอัตโนมัติ ให้ทําตามขั้นตอนต่อไปนี้

  1. หากต้องการเปิดเครื่องมือแก้ไข Apps Script ให้ไปที่ script.google.com หากเคยไป script.google.com เป็นครั้งแรก ให้คลิกดูหน้าแดชบอร์ด
  2. คลิกโครงการใหม่
  3. ลบโค้ดใดๆ ในเครื่องมือแก้ไขสคริปต์และวางในโค้ดด้านล่าง

    เทมเพลต/สแตนด์อโลน/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. เปิดอีเมลแล้วคลิกลิงก์เพื่อเปิดเอกสารที่คุณสร้าง

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