How to get length of variable array or output HTTP?
Question
Friday, May 24, 2019 5:40 PM
I have one variable array
[
{"name":"abc",
"id" : "123"},
{"name":"xyz",
"id" : "666"}
]
Variable action is `Initialize_variable` I want a array count so user expression like
@length(body('Initialize_variable')?['value'])
but getting null and error here. I also want to take same outout length for HTTP output which is giving me json output.
output -2 in above case
any syntax correction anyone? thanks
SE
All replies (6)
Saturday, May 25, 2019 7:42 PM âś…Answered | 1 vote
Alright, two things:
First of all you need to reference testvar and not Initialize_Variable.
Also length returns an Integer not a string.
So the following will work (tested):
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Initialize_variable": {
"inputs": {
"variables": [
{
"name": "testvar",
"type": "Array",
"value": [
{
"name": "1"
},
{
"name": "2"
}
]
}
]
},
"runAfter": {},
"type": "InitializeVariable"
},
"Initialize_variable_2": {
"inputs": {
"variables": [
{
"name": "countlength",
"type": "Integer",
"value": "@length(variables('testvar'))"
}
]
},
"runAfter": {
"Initialize_variable": [
"Succeeded"
]
},
"type": "InitializeVariable"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {},
"triggers": {
"manual": {
"inputs": {
"schema": {}
},
"kind": "Http",
"type": "Request"
}
}
}
}
Morten la Cour
Friday, May 24, 2019 7:22 PM | 1 vote
Try this:
@length(variables('Initialize_variable'))
Morten la Cour
Saturday, May 25, 2019 9:39 AM
not working for me :(
error while save-
Failed to save logic app. The inputs of workflow run action 'Initialize_variable_2' of type 'InitializeVariable' are not valid. The variable 'Initialize_variable' must be initialized before it can be used inside action 'Initialize_variable_2'.
SE
Saturday, May 25, 2019 1:53 PM | 1 vote
Would be easier if I could see the flow, but judging by the error message, it seems like Init_variable_2 is either not executing after init_variable?
Morten la Cour
Saturday, May 25, 2019 2:04 PM
this is my logic app code
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Initialize_variable": {
"inputs": {
"variables": [
{
"name": "testvar",
"type": "Array",
"value": [
{
"name": "1"
},
{
"name": "2"
}
]
}
]
},
"runAfter": {},
"type": "InitializeVariable"
},
"Initialize_variable_2": {
"inputs": {
"variables": [
{
"name": "countlength",
"type": "String",
"value": "@length(variables('Initialize_variable'))"
}
]
},
"runAfter": {
"Initialize_variable": [
"Succeeded"
]
},
"type": "InitializeVariable"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {},
"triggers": {
"manual": {
"inputs": {
"schema": {}
},
"kind": "Http",
"type": "Request"
}
}
}
}
SE
Sunday, May 26, 2019 10:01 AM
ohh got it thanks it is working :)
SE