गतिविधि और गड़बड़ियों को लॉग करना

इस गाइड में, कस्टम लॉग और गड़बड़ी के ऐसे मैसेज लिखने का तरीका बताया गया है जिनसे फ़्लो के उस चरण की समस्या हल करने में मदद मिलती है जो फ़्लो की गतिविधि टैब में नहीं चलता है.

डिफ़ॉल्ट रूप से, गतिविधि टैब में उस चरण का नाम लॉग होता है जो मेनिफ़ेस्ट फ़ाइल में तय किए गए तरीके से चलता है. किसी चरण के दौरान क्या हुआ, यह समझने के लिए आपको अपने चरण के लिए कस्टम लॉग भी लिखने चाहिए. अगर उपयोगकर्ताओं को आपके चरण को चलाने के दौरान कोई समस्या आती है, तो आपके लॉग से उन्हें यह समझने में मदद मिल सकती है कि क्या हुआ.

काम की लॉग एंट्री में दो एट्रिब्यूट होते हैं:

  • इस चिप में, उस संसाधन का हाइपरलिंक होता है जिसे चरण में बनाया या अपडेट किया गया था. उदाहरण के लिए, अगर आपके चरण में कोई 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"
                }
              ]
            }
          }
        }
      }
    };
  }
}