I have an array of strings and I want to divide it into 4 arrays. To do so I am initializing a counter and 4 arrays and adding elements in each array based on the counter once counter reaches 4 I am resetting it to 0. I am using below code. I have observed that initialize counter is not initializing the counter to 0 and increment counter also does not seem to be incrementing by 1 but some random value.
"foreachstring": {
"actions": {
"Condition": {
"actions": {
"ResetCounter": {
"inputs": {
"name": "ccidcounter",
"value": 0
},
"type": "SetVariable"
}
},
"else": {
"actions": {
"IncrementCCIDCounter": {
"inputs": {
"name": "ccidcounter",
"value": 1
},
"type": "IncrementVariable"
}
}
},
"expression": {
"and": [
{
"equals": [
"@variables('ccidcounter')",
4
]
}
]
},
"runAfter": {
"SwitchOnCounter": [
"SUCCEEDED"
]
},
"type": "If"
},
"SwitchOnCounter": {
"cases": {
"Case_0": {
"actions": {
"AppendToArr1": {
"inputs": {
"name": "arr1",
"value": "@items('foreachstring')"
},
"type": "AppendToArrayVariable"
}
},
"case": 0
},
"Case_1": {
"actions": {
"AppendToArr2": {
"inputs": {
"name": "arr2",
"value": "@items('foreachstring')"
},
"type": "AppendToArrayVariable"
}
},
"case": 1
},
"Case_2": {
"actions": {
"AppendToArr3": {
"inputs": {
"name": "arr3",
"value": "@items('foreachstring')"
},
"type": "AppendToArrayVariable"
}
},
"case": 2
},
"Case_3": {
"actions": {
"AppendToArr4": {
"inputs": {
"name": "arr4",
"value": "@items('foreachstring')"
},
"type": "AppendToArrayVariable"
}
},
"case": 3
}
},
"default": {
"actions": {}
},
"expression": "@variables('ccidcounter')",
"type": "Switch"
}
},
"foreach": "@body('ParseJSONFromCosmosQuery')?['value']",
"runAfter": {
"initialize_counter": [
"SUCCEEDED"
]
},
"type": "Foreach"
},
"initialize_arr1": {
"inputs": {
"variables": [
{
"name": "arr1",
"type": "array",
"value": []
}
]
},
"runAfter": {
"ParseJSONFromCosmosQuery": [
"SUCCEEDED"
]
},
"type": "InitializeVariable"
},
"initialize_arr2": {
"inputs": {
"variables": [
{
"name": "arr2",
"type": "array",
"value": []
}
]
},
"runAfter": {
"initialize_arr1": [
"SUCCEEDED"
]
},
"type": "InitializeVariable"
},
"initialize_arr3": {
"inputs": {
"variables": [
{
"name": "arr3",
"type": "array",
"value": []
}
]
},
"runAfter": {
"initialize_arr2": [
"SUCCEEDED"
]
},
"type": "InitializeVariable"
},
"initialize_arr4": {
"inputs": {
"variables": [
{
"name": "arr4",
"type": "array",
"value": []
}
]
},
"runAfter": {
"initialize_arr3": [
"SUCCEEDED"
]
},
"type": "InitializeVariable"
},
"initialize_counter": {
"inputs": {
"variables": [
{
"name": "ccidcounter",
"type": "integer",
"value": 0
}
]
},
"runAfter": {
"initialize_arr4": [
"SUCCEEDED"
]
},
"type": "InitializeVariable"
}