我正在通過在我的邏輯應用程式中使用范圍來處理錯誤。如果出現錯誤,我會得到引發錯誤的范圍的結果。
問題是結果包含相關范圍內包含的所有步驟的所有結果。這看起來像這樣(縮短版):
{
"statusCode": "500",
"body": [
{
"name": "Compose_Final",
"startTime": "2021-10-30T07:05:25.5184987Z",
"endTime": "2021-10-30T07:05:25.5341199Z",
"trackingId": "104822d9-2680-4917-bde4-b09132e32de5",
"clientTrackingId": "08585660294078874488209628375CU22",
"code": "ActionSkipped",
"status": "Skipped",
"error": {
"code": "ActionConditionFailed",
"message": "Die Ausführung der Vorlagenaktion \"Compose_Final\" wird übersprungen: Die runAfter-Bedingung \"Set_variable\" wird nicht erfüllt: Erwartete Statuswerte: Succeeded. Tats?chlicher Wert: Failed."
}
},
{
"name": "For_each_Gehaltslauf",
"inputs": {
"foreachItems": [
"e80796aa-b3e0-eb11-bacb-000d3abb215c"
]
},
"inputsMetadata": {
"foreachItemsCount": 1
},
"startTime": "2021-10-30T07:04:38.3305884Z",
"endTime": "2021-10-30T07:05:25.4716195Z",
"trackingId": "3e23002a-d3ee-4696-b05c-c6ba89403f36",
"clientTrackingId": "08585660294078874488209628375CU22",
"status": "Succeeded"
},
{
"name": "Send_an_email_(V2)",
"startTime": "2021-10-30T07:05:25.5497465Z",
"endTime": "2021-10-30T07:05:25.5497465Z",
"trackingId": "8d60b137-3094-4b79-b099-04ce50bb3875",
"clientTrackingId": "08585660294078874488209628375CU22",
"code": "ActionSkipped",
"status": "Skipped",
"error": {
"code": "ActionConditionFailed",
"message": "Die Ausführung der Vorlagenaktion \"Send_an_email_(V2)\" wird übersprungen: Die runAfter-Bedingung \"Compose_Final\" wird nicht erfüllt: Erwartete Statuswerte: Succeeded. Tats?chlicher Wert: Skipped."
}
},
{
"name": "Set_variable",
"startTime": "2021-10-30T07:05:25.5028731Z",
"endTime": "2021-10-30T07:05:25.5028731Z",
"trackingId": "71ee5d61-8029-4a35-ab52-2b80fef031dd",
"clientTrackingId": "08585660294078874488209628375CU22",
"code": "BadRequest",
"status": "Failed",
"error": {
"code": "InvalidTemplate",
"message": "Vorlagensprachausdrücke in den Eingaben der Aktion \"Set_variable\" in Zeile \"1\" und Spalte \"2098\" k?nnen nicht verarbeitet werden: Versuch zum Teilen eines Integral- oder Dezimalwerts durch null in Funktion \"div\".."
}
}
]
}
我想只回傳失敗步驟的回應。所以我需要獲取狀態為“失敗”的步驟的“訊息”。
如何從 json 中檢索此訊息?我知道我必須首先決議結果以獲得“用戶友好”的 json 表示,但現在我堅持從失敗的步驟中獲取訊息。
在這個例子中,這將是這個:
{
"name": "Set_variable",
"startTime": "2021-10-30T07:05:25.5028731Z",
"endTime": "2021-10-30T07:05:25.5028731Z",
"trackingId": "71ee5d61-8029-4a35-ab52-2b80fef031dd",
"clientTrackingId": "08585660294078874488209628375CU22",
"code": "BadRequest",
"status": "Failed",
"error": {
"code": "InvalidTemplate",
"message": "Vorlagensprachausdrücke in den Eingaben der Aktion \"Set_variable\" in Zeile \"1\" und Spalte \"2098\" k?nnen nicht verarbeitet werden: Versuch zum Teilen eines Integral- oder Dezimalwerts durch null in Funktion \"div\".."
}
}
非常感謝任何建議。
uj5u.com熱心網友回復:
您將需要遍歷“正文”中的每個專案。首先決議每個專案并檢查“狀態”是否=“失敗”。如果是,則將其附加到新的陣列變數并回傳該結果。這顯示在附圖中。

JSON 代碼如下。
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"For_each": {
"actions": {
"Condition_2": {
"actions": {
"Append_to_array_variable": {
"inputs": {
"name": "finalresult",
"value": "@items('For_each')"
},
"runAfter": {},
"type": "AppendToArrayVariable"
}
},
"expression": {
"and": [
{
"equals": [
"@body('Parse_JSON')?['status']",
"Failed"
]
}
]
},
"runAfter": {
"Parse_JSON": [
"Succeeded"
]
},
"type": "If"
},
"Parse_JSON": {
"inputs": {
"content": "@items('For_each')",
"schema": {
"properties": {
"clientTrackingId": {
"type": "string"
},
"code": {
"type": "string"
},
"endTime": {
"type": "string"
},
"error": {
"properties": {
"code": {
"type": "string"
},
"message": {
"type": "string"
}
},
"type": "object"
},
"name": {
"type": "string"
},
"startTime": {
"type": "string"
},
"status": {
"type": "string"
},
"trackingId": {
"type": "string"
}
},
"type": "object"
}
},
"runAfter": {},
"type": "ParseJson"
}
},
"foreach": "@triggerBody()?['body']",
"runAfter": {
"Initialize_variable": [
"Succeeded"
]
},
"type": "Foreach"
},
"Initialize_variable": {
"inputs": {
"variables": [
{
"name": "finalresult",
"type": "array",
"value": []
}
]
},
"runAfter": {},
"type": "InitializeVariable"
},
"Response": {
"inputs": {
"body": "@variables('finalresult')",
"statusCode": 200
},
"kind": "Http",
"runAfter": {
"For_each": [
"Succeeded"
]
},
"type": "Response"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {},
"triggers": {
"manual": {
"inputs": {
"schema": {
"properties": {
"body": {
"items": {
"properties": {
"clientTrackingId": {
"type": "string"
},
"code": {
"type": "string"
},
"endTime": {
"type": "string"
},
"error": {
"properties": {
"code": {
"type": "string"
},
"message": {
"type": "string"
}
},
"type": "object"
},
"inputs": {
"properties": {
"foreachItems": {
"items": {
"type": "string"
},
"type": "array"
}
},
"type": "object"
},
"inputsMetadata": {
"properties": {
"foreachItemsCount": {
"type": "integer"
}
},
"type": "object"
},
"name": {
"type": "string"
},
"startTime": {
"type": "string"
},
"status": {
"type": "string"
},
"trackingId": {
"type": "string"
}
},
"required": [
"name",
"startTime",
"endTime",
"trackingId",
"clientTrackingId",
"status"
],
"type": "object"
},
"type": "array"
},
"statusCode": {
"type": "string"
}
},
"type": "object"
}
},
"kind": "Http",
"type": "Request"
}
}
},
"parameters": {}
}
uj5u.com熱心網友回復:
這似乎是應該使用
結果:

轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/346066.html
