applyWhen queryLogicalExpression not working

Certified Senior Developer

Hi, Im facing an issue in queryLogicalExpression where 'AND' operator is used and there are 3 query filters in it with applyWhen parameter is passed which is evaluated as false in all the 3 filters but still this expression got executed instead of ignoring it. Is the applyWhen parameter will work only for separate queryFilter and not for the filters added in logical expression? Could someone help me to understand the behaviour?

Thanks

  Discussion posts and replies are publicly visible

Parents
  • Yes, applyWhen absolutely works inside a!queryLogicalExpression().

    The reason your query is still running instead of being ignored is : When all filters inside a logical expression evaluate to false, Appian empties the list entirely. In Appian, an empty filter list doesn’t mean "ignore this query" or "return nothing", it means "return everything." The system treats it as a blank canvas with no restrictions, which is why your query still executes and fetches data.

    could u give us more clarity on how and where you are applying the applywhen parameter. a code snippet would be helpful.

  • 0
    Certified Senior Developer
    in reply to EREN_YEAGER

    Sure, it's a nested expression where in all the queryLogicalExpression highlighted in the box contain applyWhen parameter and it is false so I've expected the top level queryLogicalExpression (highlighted in yellow) should be skipped

Reply Children
  • To make the yellow expression block disappear entirely when those conditions are met, you need to lift the applyWhen logic up to the parent layer. Instead of calling this parameter inside the individual a!queryFilter blocks, you must apply it directly to the top-level a!queryLogicalExpression that you want skipped.

    Note : if you want an entire logical block (like the one highlighted in yellow) to be ignored based on a condition, the applyWhen must live on that specific block. Relying on inner filters to turn false will only clear out those specific inner filters, leaving the outer OR structure active and running.

  • +1
    Certified Lead Developer
    in reply to sugithrag

    applyWhen exists only on a!queryFilter(), not on a!queryLogicalExpression().
    It drops just that one filter - it never skips a whole logical-expression block. When all leaf filters drop, the empty nested expressions still get processed, so your top-level block isn't ignored.

    Build the blocks conditionally - if(<cond>, a!queryLogicalExpression(...), null) and a!flatten() the list so nulls fall out.