Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Critical: Logic app is using variable value of the first foreach iteration #831

Closed
brolifen opened this issue Jul 14, 2023 · 2 comments
Closed

Comments

@brolifen
Copy link

brolifen commented Jul 14, 2023

Describe the Bug

A foreach loop goes through all items in an array. For each item a variable is set in the iteration and used in a HTTP request. Here is the setup:

image

As you can see the connectionIdentifier variable is set first and then used within the condition block.

However in practise what I see is that the variable value of the previous iteration is used when processing the second item in the array.

image

image

Am I doing something wrong here? What did the reference get the value of the previous iteration?

Some more testing I did:

  • This issue is also 100% reproducible see the below shared workflow.
  • Same issue can be reproduced on two completely different subscriptions linked to completely different Entra ID tenants
  • The same workflow on the Power Automate platform works as expected.
  • Tried in both Eest US as West Europe region it seems to be present in all regions.
  • The Issue ONLY occurs in a Foreach Loop, a Do Untill loop works as expected

Plan Type

consumption

Steps to Reproduce the Bug or Issue

  1. Create a new consumption based Logic App in West Europe
  2. Copy and paste the workflow JSON
  3. Run the Workflow
  4. Notice the variable value is not respected when called in the condition in the foreach iteration

Workflow JSON

{
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {
            "For_each": {
                "actions": {
                    "Set_userName_value": {
                        "inputs": {
                            "name": "userName",
                            "value": "@{item()?['name']}"
                        },
                        "runAfter": {},
                        "type": "SetVariable"
                    },
                    "Show_userName_value": {
                        "inputs": "@variables('userName')",
                        "runAfter": {
                            "Set_userName_value": [
                                "Succeeded"
                            ]
                        },
                        "type": "Compose"
                    }
                },
                "foreach": "@variables('UserArray')",
                "runAfter": {
                    "Initialize_UserArray_variable": [
                        "Succeeded"
                    ]
                },
                "type": "Foreach"
            },
            "Initialize_UserArray_variable": {
                "inputs": {
                    "variables": [
                        {
                            "name": "UserArray",
                            "type": "array",
                            "value": [
                                {
                                    "name": "Alice",
                                    "number": "46374"
                                },
                                {
                                    "name": "Bob",
                                    "number": "65378"
                                },
                                {
                                    "name": "John",
                                    "number": "22654"
                                }
                            ]
                        }
                    ]
                },
                "runAfter": {
                    "Initialize_userName_variable": [
                        "Succeeded"
                    ]
                },
                "type": "InitializeVariable"
            },
            "Initialize_userName_variable": {
                "inputs": {
                    "variables": [
                        {
                            "name": "userName",
                            "type": "string"
                        }
                    ]
                },
                "runAfter": {},
                "type": "InitializeVariable"
            }
        },
        "contentVersion": "1.0.0.0",
        "outputs": {},
        "parameters": {},
        "triggers": {
            "manual": {
                "inputs": {},
                "kind": "Http",
                "operationOptions": "IncludeAuthorizationHeadersInOutputs",
                "type": "Request"
            }
        }
    },
    "parameters": {}
}

Screenshots or Videos

No response

Additional context

This is ONLY affecting the foreach loop. The do until loop respects the variable value correctly.

AB#24543921

@rllyy97
Copy link

rllyy97 commented Jul 17, 2023

Hi @brolifen, I saw you closed the issue, are you still able to reproduce it or did you reach some sort of resolution?

@brunoscota
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants