本指南說明如何編寫自訂記錄和錯誤訊息,協助您在流程「活動」分頁中,排解無法執行的流程步驟問題。
根據預設,「活動」分頁會記錄步驟名稱,如資訊清單檔案中所定義。為協助您瞭解步驟執行期間發生的情況,您也應為步驟編寫自訂記錄。如果使用者在執行步驟時遇到非預期行為,記錄檔可協助他們瞭解發生了什麼事。
實用的記錄項目有兩項屬性:
- 這個方塊包含步驟建立或更新的資源超連結。舉例來說,如果步驟會建立 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"
}
]
}
}
}
}
};
}
}