Check if database query return any results

Whats the condition I need to use to check if a database query return results? on the format condition for an object is not available the has items?

I have use the count but I think is not working.

You’re trying to format a variable?
You need to apply it to an array

I am on server connect I have a database query I want to if the database query is empy set value to a variable.

Set a condition action with the condition query
So you can use then and else.

2 Likes

In same case I usually use method .count()>0

3 Likes

I'm not sure if it as a bug or expected behavior, but on Wappler 6.7.3 your approach returns THEN even if array is empty.

image

Interesting, never had issues.
What if you move the query outside the first condition?

Expressions are based on JavaScript, for a condition it checks if the value is truthy and an empty array is truthy.

@patrick meaning the only way to check if database query returns nothing is- .count()>0?

1 Like

yes, the count formatter is the best way to check if a collection is empty.

2 Likes