-1

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.

rados233
  • 3
  • 2

1 Answers1

0

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.

enter image description here

Then use another variable to store the result filter(s).

enter image description here

Now add a "Condition" to judge if filter1 is not equal to "empty".

enter image description here

If true, add another condition "Condition 2" to judge if filter2 is not equal to "empty" and set the value for filterResult.

enter image description here

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.

enter image description here

After that, we can use filterResult in "Get entities". The expression in below screenshot is trim(variables('filterResult')).

enter image description here

Hury Shen
  • 14,948
  • 1
  • 9
  • 18
  • is it possible to implement this logic in Get entitites action using Odata in get Filter query ? Thank you for your help – rados233 May 25 '21 at 15:08
  • @rados233 You can implement it by a long expression: `if(equals(variables('filter1'), ''), if(equals(variables('filter2'), ''), '', variables('filter2')), if(equals(variables('filter2'), ''), variables('filter1'), concat(variables('filter1'), ' and ', variables('filter2'))))` in "Get entities" filter query. – Hury Shen May 26 '21 at 05:44
  • @rados233 If it helps your problem, please [accept it as answer](https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work/5235#5235) (click on the check mark beside my answer to toggle it from greyed out to filled in). Thanks in advance. – Hury Shen May 26 '21 at 05:44