if-statementgetodataazure-logic-appsazure-tablequery

Azure logic apps Odata filter query with if statment on two columns


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.


Solution

  • 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