บันทึกกิจกรรมและข้อผิดพลาด

คู่มือนี้จะอธิบายวิธีเขียนบันทึกและข้อความแสดงข้อผิดพลาดที่กำหนดเองซึ่งช่วย แก้ปัญหาขั้นตอนโฟลว์ที่ทำงานไม่สำเร็จในแท็บกิจกรรมโฟลว์

โดยค่าเริ่มต้น แท็บกิจกรรมจะบันทึกชื่อของขั้นตอนที่เรียกใช้ตามที่กำหนดไว้ใน ไฟล์ Manifest คุณควรเขียนบันทึกที่กำหนดเองสำหรับขั้นตอนด้วยเพื่อช่วยให้เข้าใจสิ่งที่เกิดขึ้นระหว่างการเรียกใช้ขั้นตอน หากผู้ใช้พบพฤติกรรมที่ไม่คาดคิดขณะเรียกใช้ขั้นตอนของคุณ บันทึกจะช่วยให้ผู้ใช้เข้าใจสิ่งที่เกิดขึ้นได้

รายการบันทึกที่เป็นประโยชน์จะมีแอตทริบิวต์ 2 รายการ ดังนี้

  • ชิปที่มีไฮเปอร์ลิงก์ไปยังทรัพยากรที่ขั้นตอนสร้างหรืออัปเดต เช่น หากขั้นตอนของคุณสร้าง Google เอกสาร ให้ใช้ชิปเพื่อ ลิงก์ไปยัง Google เอกสารที่สร้างขึ้น
  • ข้อความแสดงข้อผิดพลาดโดยละเอียดที่อธิบายสาเหตุที่ขั้นตอนทำงานไม่สำเร็จและวิธี แก้ไขปัญหา

ตัวอย่างโค้ดต่อไปนี้แสดงวิธีที่ onExecuteFunction() ของขั้นตอนสามารถบันทึกการทำงานที่สำเร็จและข้อผิดพลาดไปยังแท็บกิจกรรมได้

Apps Script

function onExecuteFunctionCreateDocument(e) {

  // true if the document is successfully created, false if something goes wrong.
  var successfulRun = createDocument();

  // If successful, return an activity log linking to the created document.
  if (successfulRun == true) {
    return {
      "hostAppAction": {
        "workflowAction": {
          "returnOutputVariablesAction": {
            "variableValues": [
              {}
            ],
            "log": {
              "textFormatElements": [
                {
                  "text": "Created Google Doc"
                },
                {
                  "chip": {
                    "icon": {
                      "materialIconName": "edit_document"
                    },
                    "url": "https://docs.google.com/document/d/{DOCUMENT}",
                    "label": "{NAMEOFDOCUMENT}"
                  }
                },
                {
                  "text": "Created doc detailing how to improve product."
                }
              ]
            },
            "trigger_log": {
              "textFormatElements": [
                {
                  "text": "Email log "
                }
              ]
            }
          }
        }
      }
    };
  }

  // Otherwise, return an activity log containing an error explaining what happened and how to resolve the issue.
  else {
    return {
      "hostAppAction": {
        "workflowAction": {
          "returnElementErrorAction": {
            "errorActionability": "NOT_ACTIONABLE",
            "errorRetryability": "NOT_RETRYABLE",
            "error_log": {
              "textFormatElements": [
                {
                  "text": "Failed to create Google Doc"
                },
                {
                  "chip": {
                    "icon": {
                      "materialIconName": "document"
                    },
                    "label": "{NAMEOFDOCUMENT}"
                  }
                },
                {
                  "text": "Unable to create Google Document because OAuth verification failed. Grant one of these authorization scopes and try again: https://www.googleapis.com/auth/documents, https://www.googleapis.com/auth/drive, https://www.googleapis.com/auth/drive.file"
                }
              ]
            }
          }
        }
      }
    };
  }
}