如何在 Azure Logic App 中实现这种条件?

How to implement this kind of condition in Azure Logic App?

我使用 Parse JSON activity:

在 Azure Logic App 中有以下 json 输出结构
[
{ "name": "John",
"working days":['monday', 'tuesday', 'friday'],
"starting hour": ['8 A.M'., '7 A.M', '8 A.M.']
},
{ "name": "Carl",
"working days":['monday', 'tuesday'],
"starting hour": ['6 A.M'., '6 A.M']
},
{ "name": "Claire",
"working days":['monday', 'wednesday', 'friday'],
"starting hour": ['8 A.M'., '6 A.M', '9 A.M.']
},
{ "name": "Lisa",
"working days":['monday', 'thursday','saturday'],
"starting hour": ['8 A.M'., '7 A.M', '8 A.M.']
}
]

我想遍历每个用户并添加一个条件,其中 "working days" 等于 tuesday 它应 return 匹配 "starting hour"。例如 7 A.M。以防约翰和 6 A.M。给卡尔。

我已经在 Parse JSON 之后添加了一个 For Each Activity 来遍历 json 来获取每个人,之后添加了另一个 For Each通过 working days。然后我添加了一个 Condition,以匹配是否是星期二。如果是,那么它 returns 'true' 作为一个布尔值。但是我怎样才能使它 return 匹配 starting hour?

也许图片有助于形象化。下面,working daystuesday 只是空白填充物。

谢谢并致以最诚挚的问候!

编辑:数组中相同数量的值,删除错误放置的引号

很难让您完成我对您问题的全部回答,但这是我的逻辑应用程序的 JSON 定义(您可以将其加载到您自己的租户中进行测试并查看它是如何工作的)这将为您提供我将采用的方法...

{
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {
            "For_Each_Name": {
                "actions": {
                    "Reset_Starting_Hour": {
                        "inputs": {
                            "name": "Starting Hour",
                            "value": "@{string('')}"
                        },
                        "runAfter": {
                            "Set_Index_=_0": [
                                "Succeeded"
                            ]
                        },
                        "type": "SetVariable"
                    },
                    "Set_Index_=_0": {
                        "inputs": {
                            "name": "Index",
                            "value": 0
                        },
                        "runAfter": {
                            "Set_Working_Days_Array_Length": [
                                "Succeeded"
                            ]
                        },
                        "type": "SetVariable"
                    },
                    "Set_Working_Days_Array_Length": {
                        "inputs": {
                            "name": "Working Days Array Length",
                            "value": "@length(items('For_Each_Name')?['working days'])"
                        },
                        "runAfter": {},
                        "type": "SetVariable"
                    },
                    "Until_Index_=_Working_Days_Array_Length": {
                        "actions": {
                            "Condition": {
                                "actions": {
                                    "Set_Starting_Hour": {
                                        "inputs": {
                                            "name": "Starting Hour",
                                            "value": "@{items('For_Each_Name')?['starting hour'][variables('Index')]}"
                                        },
                                        "runAfter": {},
                                        "type": "SetVariable"
                                    }
                                },
                                "expression": {
                                    "and": [
                                        {
                                            "equals": [
                                                "@items('For_Each_Name')?['working days'][variables('Index')]",
                                                "tuesday"
                                            ]
                                        }
                                    ]
                                },
                                "runAfter": {},
                                "type": "If"
                            },
                            "Increment_Index": {
                                "inputs": {
                                    "name": "Index",
                                    "value": 1
                                },
                                "runAfter": {
                                    "Condition": [
                                        "Succeeded"
                                    ]
                                },
                                "type": "IncrementVariable"
                            }
                        },
                        "expression": "@equals(variables('Index'), variables('Working Days Array Length'))",
                        "limit": {
                            "count": 10,
                            "timeout": "PT1H"
                        },
                        "runAfter": {
                            "Reset_Starting_Hour": [
                                "Succeeded"
                            ]
                        },
                        "type": "Until"
                    }
                },
                "foreach": "@body('Parse_JSON')",
                "runAfter": {
                    "Initialize_Index": [
                        "Succeeded"
                    ]
                },
                "runtimeConfiguration": {
                    "concurrency": {
                        "repetitions": 1
                    }
                },
                "type": "Foreach"
            },
            "Initialize_Index": {
                "inputs": {
                    "variables": [
                        {
                            "name": "Index",
                            "type": "integer"
                        }
                    ]
                },
                "runAfter": {
                    "Initialize_Starting_Hour": [
                        "Succeeded"
                    ]
                },
                "type": "InitializeVariable"
            },
            "Initialize_Starting_Hour": {
                "inputs": {
                    "variables": [
                        {
                            "name": "Starting Hour",
                            "type": "string"
                        }
                    ]
                },
                "runAfter": {
                    "Initialize_Working_Days_Array_Length": [
                        "Succeeded"
                    ]
                },
                "type": "InitializeVariable"
            },
            "Initialize_Working_Days_Array_Length": {
                "inputs": {
                    "variables": [
                        {
                            "name": "Working Days Array Length",
                            "type": "integer"
                        }
                    ]
                },
                "runAfter": {
                    "Parse_JSON": [
                        "Succeeded"
                    ]
                },
                "type": "InitializeVariable"
            },
            "Parse_JSON": {
                "inputs": {
                    "content": [
                        {
                            "name": "John",
                            "starting hour": [
                                "8 A.M.",
                                "7 A.M.",
                                "8 A.M."
                            ],
                            "working days": [
                                "monday",
                                "tuesday",
                                "friday"
                            ]
                        },
                        {
                            "name": "Carl",
                            "starting hour": [
                                "6 A.M.",
                                "6 A.M."
                            ],
                            "working days": [
                                "monday",
                                "tuesday"
                            ]
                        },
                        {
                            "name": "Claire",
                            "starting hour": [
                                "8 A.M.",
                                "6 A.M.",
                                "9 A.M"
                            ],
                            "working days": [
                                "monday",
                                "wednesday",
                                "friday"
                            ]
                        },
                        {
                            "name": "Lisa",
                            "starting hour": [
                                "8 A.M.",
                                "7 A.M.",
                                "8 A.M."
                            ],
                            "working days": [
                                "monday",
                                "thursday",
                                "saturday"
                            ]
                        }
                    ],
                    "schema": {
                        "items": {
                            "properties": {
                                "name": {
                                    "type": "string"
                                },
                                "starting hour": {
                                    "items": {
                                        "type": "string"
                                    },
                                    "type": "array"
                                },
                                "working days": {
                                    "items": {
                                        "type": "string"
                                    },
                                    "type": "array"
                                }
                            },
                            "required": [
                                "name",
                                "working days",
                                "starting hour"
                            ],
                            "type": "object"
                        },
                        "type": "array"
                    }
                },
                "runAfter": {},
                "type": "ParseJson"
            }
        },
        "contentVersion": "1.0.0.0",
        "outputs": {},
        "parameters": {},
        "triggers": {
            "Recurrence": {
                "evaluatedRecurrence": {
                    "frequency": "Month",
                    "interval": 12
                },
                "recurrence": {
                    "frequency": "Month",
                    "interval": 12
                },
                "type": "Recurrence"
            }
        }
    },
    "parameters": {}
}

我回答的前提是确定每个 working days 数组中有多少项,然后从那里开始循环(一直递增索引变量),如果找到 星期二作为工作日,它将从同一索引中获取关联的开始时间值。

注意:每个数组的长度应该相同,否则可能会出现问题。

还有一点要指出,这仅在 For Each Name 操作的并发设置为 1 时才有效 ...

如果您不知道它在哪里,您可以在操作本身的设置中找到它。