Query with conditional based on select widget having a selection or not

I’m able to filter a table based on a query, and to use the value of a select widget in that query. What I’m having trouble doing is having a conditional in the query to use that select value if it exists, but to do something else if it doesn’t.

IF ({{TestNameFilter.selectedOptionValue}} != 'undefined')
    SELECT TestName, etc. FROM table...
          WHERE SetId = '{{GetActiveSuite.data[0].Id}}' AND code = '{{SourceCodeInput.text}}' AND TestName = '{{TestNameFilter.selectedOptionValue}}';

ELSE
        SELECT TestName, etc. FROM table...
          WHERE SetId = '{{GetActiveSuite.data[0].Id}}' AND code = '{{SourceCPIDInput.text}}';

This works fine for detecting if the select is empty, but crashes if it is selected. In that case, IF ('{{TestNameFilter.selectedOptionValue}}' != 'undefined') (note that added single quotes) works, but it doesn’t work if the select is empty.

How can I get it to work in both cases?

TIA!

Bump - now that we’re all back from holiday breaks :slight_smile: Has anybody done this before? Feels like a pretty common use case

Thx!

The if condition ({{TestNameFilter.selectedOptionValue}}) should work just fine, You dont need to check undefined.

I would like to understand what do you mean by a crash, are you seeing an error? Or the whole app crashes, I dont see why this fails.

TIP: IMO You can also do this with ternary operators, Thats much more cleaner.

Thanks for the reply - just getting back to this project now. Neither ({{TestNameFilter.selectedOptionValue}}) nor ('{{TestNameFilter.selectedOptionValue}}') are working when the referenced dropdown has no selection. I get an error in the AS console: An expression of non-boolean type specified in a context where a condition is expected, near 'SELECT'. If I replace that term with (1 = 2), the query runs fine.

It seems like maybe something has changed. The bare quantity still doesn’t work, but ('{{TestNameFilter.selectedOptionValue}}' != 'null') works for both cases, and seems to be the answer. Originally, I never got null as a value, only undefined.

I am seeing this variable working fine, I tried reproducing the error but could not, check out the screenshots below. Anyways if it works for you already, its great.