Neo
Neo

Reputation: 16219

Unable to set value to variable it always take initial value in logic app

I have one variable I set a default value as 0.

In for_each I'm setting new value to startIndex variable and use that variable in For_each but still it is using old 0 value.

logic app code -

{
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {
            "For_each_2": {
                "actions": {
                    "Set_variable_3": {
                        "inputs": {
                            "name": "output",
                            "value": "@{split(items('For_each_2'),':')[0]}:@{substring(variables('mydata'),variables('startindex'),int(split(items('For_each_2'),':')[1]))}"
                        },
                        "runAfter": {},
                        "type": "SetVariable"
                    },
                    "Set_variable_4": {
                        "inputs": {
                            "name": "startIndex",
                            "value": "@int(split(items('For_each_2'),':')[1])"
                        },
                        "runAfter": {
                            "Set_variable_3": [
                                "Succeeded"
                            ]
                        },
                        "type": "SetVariable"
                    }
                },
                "foreach": "@variables('splitvar')",
                "runAfter": {
                    "Initialize_variable_9": [
                        "Succeeded"
                    ]
                },
                "type": "Foreach"
            },
            "Initialize_variable_5": {
                "inputs": {
                    "variables": [
                        {
                            "name": "mydata",
                            "type": "String",
                            "value": "abcdefg"
                        }
                    ]
                },
                "runAfter": {},
                "type": "InitializeVariable"
            },
            "Initialize_variable_6": {
                "inputs": {
                    "variables": [
                        {
                            "name": "key",
                            "type": "String",
                            "value": "AA:3;BB:2"
                        }
                    ]
                },
                "runAfter": {
                    "Initialize_variable_5": [
                        "Succeeded"
                    ]
                },
                "type": "InitializeVariable"
            },
            "Initialize_variable_7": {
                "inputs": {
                    "variables": [
                        {
                            "name": "splitvar",
                            "type": "Array",
                            "value": "@split(variables('key'),';')"
                        }
                    ]
                },
                "runAfter": {
                    "Initialize_variable_6": [
                        "Succeeded"
                    ]
                },
                "type": "InitializeVariable"
            },
            "Initialize_variable_8": {
                "inputs": {
                    "variables": [
                        {
                            "name": "output",
                            "type": "String"
                        }
                    ]
                },
                "runAfter": {
                    "Initialize_variable_7": [
                        "Succeeded"
                    ]
                },
                "type": "InitializeVariable"
            },
            "Initialize_variable_9": {
                "inputs": {
                    "variables": [
                        {
                            "name": "startIndex",
                            "type": "Integer",
                            "value": 0
                        }
                    ]
                },
                "runAfter": {
                    "Initialize_variable_8": [
                        "Succeeded"
                    ]
                },
                "type": "InitializeVariable"
            }
        },
        "contentVersion": "1.0.0.0",
        "outputs": {},
        "parameters": {},
        "triggers": {
            "manual": {
                "inputs": {
                    "schema": {}
                },
                "kind": "Http",
                "type": "Request"
            }
        }
    }
}

Upvotes: 1

Views: 1661

Answers (1)

AdAstra
AdAstra

Reputation: 1984

You need to enable concurrency control on the for each action. As default the for each action run with a Degree of Parallelism set to 20. So it runs the action 20 times in parallel as the default behavior. Turn it down to 1.

Settings[1]

Degree of Parallelism]2

Upvotes: 5

Related Questions