I am trying to check the files count in array and perform below actions
- If Count is 0, No action
- If Count is 1, perform a specific action
- If Count is greater than 1, perform another set of action.
I am using length expression to check the array file count using length(body('Filter_blobs_which_added_in_last_15min'))
Currently I am following below logic ( 2 step condition, first check if the value is zero, and then check if value is 1 or greater than 1). Is there anyway I can combine this into single condition ?
CodePudding user response:
You can achieve this by using Switch condition
in your workflow as shown below.
We have created a logic app which will calculate, the number of blobs present in the storage account, using compose & length function (we have calculated the number of blobs) based on the blob count the switch statement associates actions will be executed further.
And also we have tested this in our local environment which is working fine.
Here is the logic app Designer Image:
Here is the code view of the logic app :
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Compose": {
"inputs": "@length(body('Lists_blobs_(V2)')?['value'])",
"runAfter": {
"Lists_blobs_(V2)": [
"Succeeded"
]
},
"type": "Compose"
},
"Lists_blobs_(V2)": {
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['azureblob']['connectionId']"
}
},
"method": "get",
"path": "/v2/datasets/@{encodeURIComponent(encodeURIComponent('AccountNameFromSettings'))}/foldersV2/@{encodeURIComponent(encodeURIComponent('JTJmY29udDE='))}",
"queries": {
"nextPageMarker": "",
"useFlatListing": false
}
},
"metadata": {
"JTJmY29udDE=": "/cont1"
},
"runAfter": {},
"type": "ApiConnection"
},
"Switch": {
"cases": {
"Case": {
"actions": {
"Compose_4": {
"inputs": "length of blob are @{outputs('Compose')}",
"runAfter": {},
"type": "Compose"
}
},
"case": 0
},
"Case_2": {
"actions": {
"Compose_3": {
"inputs": "length of blobs are @{outputs('Compose')}",
"runAfter": {},
"type": "Compose"
}
},
"case": 1
}
},
"default": {
"actions": {
"Compose_2": {
"inputs": "length of blobs are @{outputs('Compose')}",
"runAfter": {},
"type": "Compose"
}
}
},
"expression": "@outputs('Compose')",
"runAfter": {
"Compose": [
"Succeeded"
]
},
"type": "Switch"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {
"$connections": {
"defaultValue": {},
"type": "Object"
}
},
"triggers": {
"Recurrence": {
"evaluatedRecurrence": {
"frequency": "Minute",
"interval": 3
},
"recurrence": {
"frequency": "Minute",
"interval": 3
},
"type": "Recurrence"
}
}
},
"parameters": {
"$connections": {
"value": {
"azureblob": {
"connectionId": "/subscriptions/<subId>/resourceGroups/<rgName>/providers/Microsoft.Web/connections/azureblob",
"connectionName": "azureblob",
"id": "/subscriptions/<subId>/providers/Microsoft.Web/locations/eastus/managedApis/azureblob"
}
}
}
}
}
Here is the sample output for reference: