How to apply contains expression to filter array of string in Azure Logic Apps
Hi Team,
I have scenario where I need to filter of array of object with two properties i.e. ID and alias.
like below in Azure Logic Apps
[ { "alias": "_V2_abc.Svc_CI", "definitionId": 63 }, { "alias": "_V2_abcTEST.Svc_CI", "definitionId": 64 } ]
Now I want to filter this above array with contains expression on alias property but its returning null or empty array.
I tried all the ways like to convert to string etc. but still no luck.
Can anyone have faced this issue then help me here to resolve this.
Regards,Dattatray
Azure Logic Apps
-
Khadeer Ali 1,130 Reputation points • Microsoft Vendor
2024-10-10T07:05:32.3+00:00 Hi @Dattatray Pise ,
Welcome to the Microsoft Q&A Platform! Thank you for asking your question here.While you are using Filters on Alias and it's returning null or empty array. Please try once with contains in the Condition field, in this way the filter will check if the alias property contains the substring which was passed. If the condition is met, the object will be included in the output array.
Below is the example with the problem reference.
{ "actions": { "Filter_array": { "inputs": { "from": [ { "alias": "_V2_abc.Svc_CI", "definitionId": 63 }, { "alias": "_V2_abcTEST.Svc_CI", "definitionId": 64 } ], "conditions": [ { "left": "@item().alias", "operator": "contains", "right": "abc" } ] }, "runAfter": {}, "type": "Query" } }
Please find the reference in below link for the filter action for arrays.
If the issue persists, please do not hesitate to reach out further assistance. If you find this answer helpful, please click "Comment" and kindly upvote it.
-
Khadeer Ali 1,130 Reputation points • Microsoft Vendor
2024-10-14T00:54:13.7733333+00:00 Hi @Dattatray pise,
We haven’t heard from you on the last response and was just checking back to see if you have a resolution yet. In case if you have any resolution, please do share that same with the community as it can be helpful to others. Otherwise, will respond with more details and we will try to help.
-
DATTATRAY PISE (WIPRO LIMITED) 0 Reputation points • Microsoft Vendor
2024-10-14T07:47:12.8+00:00 Apologize for late reply.
The above condition works with if right side condition with plain text i.e. abc but not working if right side condition value come from variable. In my case that value come from variable and that value is dynamic.
Thanks,
Dattatray
-
Khadeer Ali 1,130 Reputation points • Microsoft Vendor
2024-10-14T08:24:11.1466667+00:00 Hi @DATTATRAY PISE (WIPRO LIMITED),
Thanks for coming back with a response.
From the context I could understand that the value should be coming from the Variable. In that case, we can define the values in the variable and can use the variable in the contains condition. Please check the modified example below:
{ "actions": { "Filter_array": { "inputs": { "from": [ { "alias": "_V2_abc.Svc_CI", "definitionId": 63 }, { "alias": "_V2_abcTEST.Svc_CI", "definitionId": 64 } ], "conditions": [ { "left": "@item().alias", "operator": "contains", "right": "@{variables('myVariable')}" } ] }, "runAfter": {}, "type": "Query" } }, "variables": { "myVariable": { "type": "string", "value": "abc" } } }
If the issue persists, please do not hesitate to reach out further assistance. If you find this answer helpful, please click "Comment" and kindly upvote it.
-
DATTATRAY PISE (WIPRO LIMITED) 0 Reputation points • Microsoft Vendor
2024-10-14T11:00:43.85+00:00 Hi @Khadeer Ali Shaik Kanubai,
I already tried this but it's not working as expected, empty result got.
Thanks,
Dattatray
-
DATTATRAY PISE (WIPRO LIMITED) 0 Reputation points • Microsoft Vendor
2024-10-14T11:44:27.1066667+00:00 "actions": { "Filter_array": { "inputs": { "from": "@body('Parse_JSON_Array')", "where": "@contains(item()['alias'],variables('test'))" }, "runAfter": { "Set_variable_2": [ "Succeeded" ] }, "type": "Query" }, "Initialize_variable": { "inputs": { "variables": [ { "name": "test", "type": "string", "value": "FGG - Graph.Svc" } ] },
-
Khadeer Ali 1,130 Reputation points • Microsoft Vendor
2024-10-15T01:23:28.9533333+00:00 Hi @DATTATRAY PISE (WIPRO LIMITED),
Thanks for Responding, we would like to know more details about the issue to replicate the scenario so that we could troubleshoot.
- Please share the Similar Sample JSON data you're working with, including the alias property and any other relevant fields.
- What is the desired output or filtered result you're trying to achieve?
-
DATTATRAY PISE (WIPRO LIMITED) 0 Reputation points • Microsoft Vendor
2024-10-15T05:24:04.7033333+00:00 I want Filter result with contains variable value { "definition": { "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#", "actions": { "Filter_array": { "inputs": { "from": "@body('Parse_JSON_Array')", "where": "@contains(item()['alias'],variables('test'))" }, "runAfter": { "Set_variable_2": [ "Succeeded" ] }, "type": "Query" }, "Initialize_variable": { "inputs": { "variables": [ { "name": "test", "type": "string", "value": "FGG - Graph.Svc" } ] }, "runAfter": { "Parse_JSON_Array": [ "Succeeded" ] }, "type": "InitializeVariable" }, "Initialize_variable_Array": { "inputs": { "variables": [ { "name": "array", "type": "string" } ] }, "runAfter": { "Initialize_variable_alias": [ "Succeeded" ] }, "type": "InitializeVariable" }, "Initialize_variable_BuildIdToExclude": { "inputs": { "variables": [ { "name": "BuildIdToExclude", "type": "integer", "value": "@length(variables('definitionId'))" } ] }, "runAfter": { "Initialize_variable_Array": [ "Succeeded" ] }, "type": "InitializeVariable" }, "Initialize_variable_ReleseDefinitionId": { "inputs": { "variables": [ { "name": "ReleseDefinitionId", "type": "array", "value": [ { "alias": "_V2_Graph.Svc_CI", "definitionId": 63 }, { "alias": "_V2_GraphTEST.Svc_CI", "definitionId": 64 } ] } ] }, "runAfter": { "Initialize_variable_BuildIdToExclude": [ "Succeeded" ] }, "type": "InitializeVariable" }, "Initialize_variable_alias": { "inputs": { "variables": [ { "name": "alias", "type": "string" } ] }, "runAfter": { "Initialize_variable_definitionId": [ "Succeeded" ] }, "type": "InitializeVariable" }, "Initialize_variable_definitionId": { "inputs": { "variables": [ { "name": "definitionId", "type": "array", "value": [ 59712 ] } ] }, "runAfter": {}, "type": "InitializeVariable" }, "Parse_JSON_Array": { "inputs": { "content": "@variables('ReleseDefinitionId')", "schema": { "items": { "properties": { "alias": { "type": "string" }, "definitionId": { "type": "integer" } }, "required": [ "alias", "definitionId" ], "type": "object" }, "type": "array" } }, "runAfter": { "Initialize_variable_ReleseDefinitionId": [ "Succeeded" ] }, "type": "ParseJson" }, "Set_variable_2": { "inputs": { "name": "alias", "value": "@item()['alias']" }, "runAfter": { "Initialize_variable": [ "Succeeded" ] }, "type": "SetVariable" } }, "contentVersion": "1.0.0.0", "outputs": {}, "parameters": { "$connections": { "defaultValue": {}, "type": "Object" } }, "triggers": { "Recurrence": { "evaluatedRecurrence": { "frequency": "Month", "interval": 1, "timeZone": "India Standard Time" }, "recurrence": { "frequency": "Month", "interval": 1, "timeZone": "India Standard Time" }, "type": "Recurrence" } } }, "parameters": { "$connections": { "value": {} } } }
-
Khadeer Ali 1,130 Reputation points • Microsoft Vendor
2024-10-15T06:02:29.2366667+00:00 Hi @DATTATRAY PISE (WIPRO LIMITED),
Thanks for providing the information requested. I could not be able to see any issues apart from case sensitivity in the code snippet provided. We can improvise the code to handle case-sensitivity for alias and variables. To achieve that we can re-write where condition with lower case like below:
"where": "@contains(toLower(item()['alias']), toLower(variables('test')))"
Please try with the above condition, meanwhile I will check the same issue with internal team so that they could check and identify for any other issues.
Thank You!
-
Khadeer Ali 1,130 Reputation points • Microsoft Vendor
2024-10-16T07:09:05.8933333+00:00 Following up to see if the above comment was helpful.In case if you have any resolution please do share that same with the community as it can be helpful to others. If this answers your query, do click
Accept Answer
andYes
for was this answer helpful. And, if you have any further query do let us know. -
DATTATRAY PISE (WIPRO LIMITED) 0 Reputation points • Microsoft Vendor
2024-10-16T09:57:55.8533333+00:00 Hi @Khadeer Ali,
I checked to apply the to lower but it's not working as expected. I think issue is different, if I simply add text to apply condition its works but not working with variable.
Thanks,
Dattatray
-
Khadeer Ali 1,130 Reputation points • Microsoft Vendor
2024-10-25T03:40:10.19+00:00 Hi DATTATRAY PISE (WIPRO LIMITED), Thanks for getting back, I am unable to reproduce this issue at my end. We might need a closer look to troubleshoot this issue which can't be done over community forums. Hence, I request you to raise support ticket with Azure Technical Team so that team can connect 1:1 and assist you to resolve the issue you are facing.
In case if you don't have a support plan, please let me know.
-
DATTATRAY PISE (WIPRO LIMITED) 0 Reputation points • Microsoft Vendor
2024-11-21T09:05:05.8066667+00:00 Hello @Khadeer Ali , Can you please provide me Azure support team email alias or how to create support ticket, As I tried to create it using portal but there are no required inputs for my issue type.Thanks,
Dattatray
Sign in to comment