Good morning,
I have a unique requirement where I have to apply a filter on "Get entities" from Azure table based on a condition, filters come from HTTP get request.
There are two filters - a and b.
If both filters passed to the flow are empty, no filter is applied. If either one of the filters is not empty, the filter must be applied on that column. If both filters are not empty, the filters must be applied on both columns.
Is it possible to apply an If statement in an ODATA filter query? I can't seem to find a good answer.
For this requirement, we can just use "Condition" in logic app to implement it. It's not a smart solution, but it works.
First I use two variables to simulate your two filters from http request.
Then use another variable to store the result filter(s).
Now add a "Condition" to judge if filter1
is not equal to "empty".
If true, add another condition "Condition 2" to judge if filter2
is not equal to "empty" and set the value for filterResult
.
If false, also add another condition "Condition 3" to judge if filter2
is not equal to "empty" and set the value for filterResult
. Note: use expression string(' ')
in "Set variable 4", or it will not allow us to save the logic app.
After that, we can use filterResult
in "Get entities". The expression in below screenshot is trim(variables('filterResult'))
.