1

I hope this message finds you well. I am writing to bring to your attention an issue I have encountered while working with nested iterations in Azure Logic Apps. I believe there might be a bug or unexpected behavior that is affecting the proper execution of nested iterations within my workflows.

Description of the issue: When I have a nested iteration structure in my Azure Logic App workflow, where the second foreach loop is nested inside the first foreach loop, I am observing that the second foreach loop only iterates the same number of times as the size of the first foreach loop. However, when I remove the first foreach loop and keep only the second foreach loop, it works as expected and iterates over all the items.

This behavior suggests that there might be a problem specifically related to nested iterations within Azure Logic Apps. I have carefully reviewed the logic and configuration of my workflow, and I am confident that there are no errors in my implementation that could explain this issue.

Steps to reproduce:

Create an Azure Logic App workflow with a nested iteration structure, where a second foreach loop is placed inside the first foreach loop. Configure the iterations and ensure that the data and conditions are valid. Trigger the Logic App to execute and observe the iteration behavior. Expected behavior: The nested iterations should work correctly, with the second foreach loop iterating over all the items as defined by the data and conditions.

Actual behavior: The second foreach loop only iterates the same number of times as the size of the first foreach loop, regardless of the actual number of items in the second iteration.

Sincerely, Shubham

I tried to remove 1st foreach loop to check if there is any issue in 2nd foreach but in that case 2nd foreach is iterating correctly.

enter image description here

1
  • "I hope this message finds you well" - - on Stack Overflow, we're not exactly polite. We're straight to the point. Please don't include any greetings (hello, etc) or goodbyes (thanks for your attention, help me, etc) in your questions or answers. Commented May 24, 2023 at 14:11

1 Answer 1

2

After reproducing from my end, I can see that the nested foreach loop is working as expected. Nested foreach loop will always has mxn time complexity while calculation where m and n are sizes of 2 variables that you take. For demonstration purposes, I have taken 2 arrays (Array1 and Array2) in which Array1 has 3 items and Array2 has 6 items. For checking the size, I have taken Counter variable.

enter image description here

enter image description here

Results:

enter image description here

Here is the complete code view of my logic app

{
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {
            "Compose_-_Counter_Total_Size": {
                "inputs": "@variables('Counter')",
                "runAfter": {
                    "For_each_1": [
                        "Succeeded"
                    ]
                },
                "type": "Compose"
            },
            "For_each_1": {
                "actions": {
                    "Compose_1": {
                        "inputs": "@items('For_each_1')",
                        "runAfter": {},
                        "type": "Compose"
                    },
                    "For_each_2": {
                        "actions": {
                            "Compose_2": {
                                "inputs": "@items('For_each_2')",
                                "runAfter": {},
                                "type": "Compose"
                            },
                            "Increment_variable": {
                                "inputs": {
                                    "name": "Counter",
                                    "value": 1
                                },
                                "runAfter": {
                                    "Compose_2": [
                                        "Succeeded"
                                    ]
                                },
                                "type": "IncrementVariable"
                            }
                        },
                        "foreach": "@variables('Array2')",
                        "runAfter": {
                            "Compose_1": [
                                "Succeeded"
                            ]
                        },
                        "type": "Foreach"
                    }
                },
                "foreach": "@variables('Array1')",
                "runAfter": {
                    "Initialize_variable_-_Counter": [
                        "Succeeded"
                    ]
                },
                "type": "Foreach"
            },
            "Initialize_variable_-_Array1": {
                "inputs": {
                    "variables": [
                        {
                            "name": "Array1",
                            "type": "array",
                            "value": [
                                "a",
                                "b",
                                "c"
                            ]
                        }
                    ]
                },
                "runAfter": {},
                "type": "InitializeVariable"
            },
            "Initialize_variable_-_Array2": {
                "inputs": {
                    "variables": [
                        {
                            "name": "Array2",
                            "type": "array",
                            "value": [
                                "d",
                                "e",
                                "f",
                                "g",
                                "h",
                                "i"
                            ]
                        }
                    ]
                },
                "runAfter": {
                    "Initialize_variable_-_Array1": [
                        "Succeeded"
                    ]
                },
                "type": "InitializeVariable"
            },
            "Initialize_variable_-_Counter": {
                "inputs": {
                    "variables": [
                        {
                            "name": "Counter",
                            "type": "integer",
                            "value": 0
                        }
                    ]
                },
                "runAfter": {
                    "Initialize_variable_-_Array2": [
                        "Succeeded"
                    ]
                },
                "type": "InitializeVariable"
            }
        },
        "contentVersion": "1.0.0.0",
        "outputs": {},
        "parameters": {},
        "triggers": {
            "manual": {
                "inputs": {
                    "schema": {}
                },
                "kind": "Http",
                "type": "Request"
            }
        }
    },
    "parameters": {}
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.