如何将Azure Logic App中的For_Each循环的输出合并到单个平面阵列?

Jud*_*her 3 azure azure-logic-apps azure-app-service-envrmnt

For_Each在Azure Logic App中有一个循环,它调用另一个嵌套的Logic App.嵌套逻辑应用程序的每次迭代的结果是一个包含字符串数组的JSON对象,如下所示:

{
 "Results": ["string a", "string b"]
}
Run Code Online (Sandbox Code Playgroud)

因此,父逻辑应用程序中的For_Each循环的输出如下所示:

[
 {"Results": ["string a", "string b"]},
 {"Results": ["string c", "string d"]}
]
Run Code Online (Sandbox Code Playgroud)

我想把所有这些字符串放到一个单独的平面列表中,我可以传递给另一个动作.

我怎样才能做到这一点?是否可以使用工作流定义语言和内置函数,还是需要使用外部函数(在服务或Azure函数中)?

小智 5

使用Array Variables有一个更简单的解决方案.在顶层,在For Each循环之外,使用InitializeVariable操作声明一个变量:

"Initialize_Items_variable": {
    "inputs": {
        "variables": [
            {
                "name": "Items",
                "type": "Array",
                "value": []
            }
        ]
    },
    "runAfter": {},
    "type": "InitializeVariable"
}
Run Code Online (Sandbox Code Playgroud)

在For Each中,使用AppendToArrayVariable操作.您可以附加刚刚调用的嵌套逻辑应用程序的Response对象.

"Append_to_Items_variable": {
    "inputs": {
        "name": "Items",
        "value": "@body('Nested_Logic_App_Response')"
    },
    "runAfter": {
    },
    "type": "AppendToArrayVariable"
}
Run Code Online (Sandbox Code Playgroud)

希望能帮助到你.