Azure 逻辑应用 - 检查多个条件

Azure Logic App - Check multiple conditions

我正在尝试检查数组中的文件数并执行以下操作

  1. 如果计数为 0,则无操作
  2. 如果计数为 1,则执行特定操作
  3. 如果计数大于 1,则执行另一组操作。

我正在使用长度表达式来检查数组文件计数 length(body('Filter_blobs_which_added_in_last_15min'))

目前我遵循以下逻辑(2 步条件,首先检查值是否为零,然后检查值是否为 1 或大于 1)。无论如何我可以将它组合成一个条件吗?

您可以通过在您的工作流程中使用 Switch condition 来实现这一点,如下所示。

我们创建了一个逻辑应用程序,它将计算存储帐户中存在的 blob 数量,使用 compose & length 函数(我们已经计算出 blob 的数量)基于 switch 语句关联操作的 blob 计数进一步执行。

而且我们已经在我们的本地环境中测试了它,它运行良好。

这是逻辑应用设计器图片:

这是逻辑应用程序的代码视图:

{
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {
            "Compose": {
                "inputs": "@length(body('Lists_blobs_(V2)')?['value'])",
                "runAfter": {
                    "Lists_blobs_(V2)": [
                        "Succeeded"
                    ]
                },
                "type": "Compose"
            },
            "Lists_blobs_(V2)": {
                "inputs": {
                    "host": {
                        "connection": {
                            "name": "@parameters('$connections')['azureblob']['connectionId']"
                        }
                    },
                    "method": "get",
                    "path": "/v2/datasets/@{encodeURIComponent(encodeURIComponent('AccountNameFromSettings'))}/foldersV2/@{encodeURIComponent(encodeURIComponent('JTJmY29udDE='))}",
                    "queries": {
                        "nextPageMarker": "",
                        "useFlatListing": false
                    }
                },
                "metadata": {
                    "JTJmY29udDE=": "/cont1"
                },
                "runAfter": {},
                "type": "ApiConnection"
            },
            "Switch": {
                "cases": {
                    "Case": {
                        "actions": {
                            "Compose_4": {
                                "inputs": "length of blob are @{outputs('Compose')}",
                                "runAfter": {},
                                "type": "Compose"
                            }
                        },
                        "case": 0
                    },
                    "Case_2": {
                        "actions": {
                            "Compose_3": {
                                "inputs": "length of blobs are @{outputs('Compose')}",
                                "runAfter": {},
                                "type": "Compose"
                            }
                        },
                        "case": 1
                    }
                },
                "default": {
                    "actions": {
                        "Compose_2": {
                            "inputs": "length of blobs are @{outputs('Compose')}",
                            "runAfter": {},
                            "type": "Compose"
                        }
                    }
                },
                "expression": "@outputs('Compose')",
                "runAfter": {
                    "Compose": [
                        "Succeeded"
                    ]
                },
                "type": "Switch"
            }
        },
        "contentVersion": "1.0.0.0",
        "outputs": {},
        "parameters": {
            "$connections": {
                "defaultValue": {},
                "type": "Object"
            }
        },
        "triggers": {
            "Recurrence": {
                "evaluatedRecurrence": {
                    "frequency": "Minute",
                    "interval": 3
                },
                "recurrence": {
                    "frequency": "Minute",
                    "interval": 3
                },
                "type": "Recurrence"
            }
        }
    },
    "parameters": {
        "$connections": {
            "value": {
                "azureblob": {
                    "connectionId": "/subscriptions/<subId>/resourceGroups/<rgName>/providers/Microsoft.Web/connections/azureblob",
                    "connectionName": "azureblob",
                    "id": "/subscriptions/<subId>/providers/Microsoft.Web/locations/eastus/managedApis/azureblob"
                }
            }
        }
    }
}

这里是示例输出以供参考: