Log activity and errors

This guide explains how to write custom logs and error messages that help troubleshoot a flow step that fails to run in the flows Activity tab.

By default, the Activity tab logs the name of the step that runs as defined in its manifest file. To help you understand what happened during a step run, you should write custom logs for your step, too. If users encounter unexpected behavior while running your step, your logs can help them understand what happened.

A helpful log entry has two attributes:

  • A chip containing a hyperlink to the resource that was created or updated by the step. For example, if your step creates a Google Doc, use the chip to link to the created Google Doc.
  • A detailed error message describing why a step failed to run and how to resolve the issue.

The following code sample shows how a step's onExecuteFunction() can log a successful run and an error to the Activity tab:

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"
                }
              ]
            }
          }
        }
      }
    };
  }
}