アクティビティとエラーをログに記録する

このガイドでは、フローの [アクティビティ] タブで実行に失敗したフロー ステップのトラブルシューティングに役立つカスタムログとエラー メッセージを記述する方法について説明します。

デフォルトでは、[アクティビティ] タブには、マニフェスト ファイルで定義されているステップの名前が記録されます。ステップ実行中に何が起こったかを理解するには、ステップのカスタムログも作成する必要があります。ステップの実行中に予期しない動作が発生した場合、ログは発生した内容を把握するのに役立ちます。

有用なログエントリには次の 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"
                }
              ]
            }
          }
        }
      }
    };
  }
}