本指南介绍了如何编写自定义日志和错误消息,以帮助排查“流程”活动标签页中无法运行的流程步骤。
默认情况下,“Activity”标签页会记录在清单文件中定义的正在运行的步的名称。为了帮助您了解在执行某一步骤期间发生了什么,您还应该为该步骤编写自定义日志。如果用户在运行您的步骤时遇到意外行为,日志可以帮助他们了解发生了什么情况。
有用的日志条目具有两个属性:
- 包含指向相应步骤创建或更新的资源的超链接的条状标签。例如,如果您的步骤创建了 Google 文档,请使用功能块链接到创建的 Google 文档。
- 详细的错误消息,说明了某步未能运行的原因以及如何解决相应问题。
以下代码示例展示了步骤的 onExecuteFunction() 如何将成功运行和错误记录到“活动”标签页:
Apps 脚本
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"
}
]
}
}
}
}
};
}
}