如果基于更改的值,则Azure Logic应用条件无法循环工作

时间:2019-05-14 20:56:34

标签: azure-logic-apps

我需要编写一个简单的LogicApp,该应用程序连接到http端点,接收一些JSON,通过JSON消息循环,然后根据消息中的值将其分块提交给其他http端点。

这样做,我得出的结论是,For Each循环内的条件总是评估循环前的条件,并执行与循环前结果相匹配的路径,即使结果由于某些变量具有已在循环中更新。

我设法用下面的例子来说明问题。

{
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {
            "Compose": {
                "inputs": "@variables('TestStr')",
                "runAfter": {
                    "Compose_3": [
                        "Succeeded"
                    ]
                },
                "type": "Compose"
            },
            "Compose_3": {
                "inputs": "@variables('TestArray')",
                "runAfter": {
                    "For_each": [
                        "Succeeded"
                    ]
                },
                "type": "Compose"
            },
            "For_each": {
                "actions": {
                    "Compose_2": {
                        "inputs": "@variables('TestArray')",
                        "runAfter": {
                            "Condition": [
                                "Succeeded"
                            ]
                        },
                        "type": "Compose"
                    },
                    "Condition": {
                        "actions": {
                            "Append_to_array_variable": {
                                "inputs": {
                                    "name": "TestArray",
                                    "value": "@items('For_each')"
                                },
                                "runAfter": {},
                                "type": "AppendToArrayVariable"
                            },
                            "Set_variable_2": {
                                "inputs": {
                                    "name": "TestStr",
                                    "value": "XXXX"
                                },
                                "runAfter": {
                                    "Append_to_array_variable": [
                                        "Succeeded"
                                    ]
                                },
                                "type": "SetVariable"
                            }
                        },
                        "else": {
                            "actions": {
                                "Set_variable": {
                                    "inputs": {
                                        "name": "TestStr",
                                        "value": "not"
                                    },
                                    "runAfter": {},
                                    "type": "SetVariable"
                                }
                            }
                        },
                        "expression": {
                            "and": [
                                {
                                    "equals": [
                                        "@variables('TestStr')",
                                        "BlankValue"
                                    ]
                                }
                            ]
                        },
                        "runAfter": {},
                        "type": "If"
                    }
                },
                "foreach": "@variables('FullArray')",
                "runAfter": {
                    "Initialize_variable_3": [
                        "Succeeded"
                    ]
                },
                "type": "Foreach"
            },
            "Initialize_variable": {
                "inputs": {
                    "variables": [
                        {
                            "name": "TestStr",
                            "type": "String",
                            "value": "BlankValue"
                        }
                    ]
                },
                "runAfter": {},
                "type": "InitializeVariable"
            },
            "Initialize_variable_2": {
                "inputs": {
                    "variables": [
                        {
                            "name": "TestArray",
                            "type": "Array"
                        }
                    ]
                },
                "runAfter": {
                    "Initialize_variable": [
                        "Succeeded"
                    ]
                },
                "type": "InitializeVariable"
            },
            "Initialize_variable_3": {
                "inputs": {
                    "variables": [
                        {
                            "name": "FullArray",
                            "type": "Array",
                            "value": [
                                {
                                    "key": "value1"
                                },
                                {
                                    "key": "value2"
                                },
                                {
                                    "key": "value3"
                                }
                            ]
                        }
                    ]
                },
                "runAfter": {
                    "Initialize_variable_2": [
                        "Succeeded"
                    ]
                },
                "type": "InitializeVariable"
            }
        },
        "contentVersion": "1.0.0.0",
        "outputs": {},
        "parameters": {},
        "triggers": {
            "Recurrence": {
                "recurrence": {
                    "frequency": "Month",
                    "interval": 3
                },
                "type": "Recurrence"
            }
        }
    }
}

我希望下面的LogicApp可以执行三次循环,每次评估条件并只执行一次数组插入,而TestArray包含一个

{
  "key":"value1"
}

和字符串TestStr的值为'not'

但是实际结果似乎有所不同-TestArray包含FullArray中的所有三个条目,而TestStr是'XXXX'

我在这里想念什么?有解决方法吗?

1 个答案:

答案 0 :(得分:0)

我已经发现了这种行为的原因。如果将来有人遇到此问题,请在此处发布。

For_each循环默认情况下并行执行。这就是为什么在循环开始之前针对所有迭代评估条件的原因。

有一种方法可以将其关闭-在Settings中,您可以打开并发控制并将parallelism设置为1