Reputation: 11
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.
Upvotes: 1
Views: 912
Reputation: 8244
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.
Results:
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": {}
}
Upvotes: 2