Query Event Handler

I know that event handlers can be triggered if a query fails to run successfully, however, is there a way to trigger an event handler if the query returns zero records?

Hi tomm!
Sure thing :-). Make a success handler with a requirement to see if it returned 0 records;

Thanks for the response, but this does not seem to be working either. It said that self.data.length is undefined, so I changed it to the name of the query (query1) and that says the same thing. What I'm trying to do is go to another app if the query returns 1 or more records. So, I set action to 'Go to app' and enterd the app I want it to go to. I then included your code in the 'Only run when" box.

Hey @tomm!

It might help if you can post and example of the data your query is returning since you might need to fit the self.data.length syntax to match your query's particular structure.

For instance, SQL queries return objects of arrays so self.data.some_column_name.length or formatDataAsArray(self.data).length can work as alternatives. The structure of REST queries, in contrast, can vary widely and usually need a unique syntax.

For reference - a greate place to check is in the Retool debug panel! (lower right corner of your app)
image

1 Like