How to add "No Configuration Found" message when no data returned from DB

Hi Team,

I am new to Retool. I am using Query Json with SQL option to return data from MongoDB.
It is working fine, however I want to add one message, if no data is there in DB for search. I believe need to write transformer.
Below is my query:

select 
  product, 
  expressions, 
  concat_ws(',',field_names) as field_names 
from 
  {{ResultValidationMapping.data}} 
where
  CASE LEN({{textInput1.value}}) 
    WHEN 0 THEN field_names = field_names
    ELSE {{textInput1.value}} in field_names
  END

Please help me to solve this issue.

Thanks,
Lalitha.C

Welcome to the forum!
Since you're using Query JSON with SQL, there would not be a request against the database so there isn't a message coming from there. Instead you can use the Success Event handler and add logic that says if there is nothing returned then do something (open a notification, etc.)
Screenshot 2022-12-05 at 12.44.50 PM
You're using Success because technically, the query you're running won't fail. At least as far as I can see...

You can also use a Transformer to check the data and if nothing is found you can set the data to a message saying No Configuration found and the populate whatever component you want to display the message in with that data.

Thank you Scott.
Could you please help me how to check whether data exists or not in transformer or provide me any example.

Thanks,
Lalitha.C

Hey @lalitha1024, welcome to the fam :hugs:

Continuing on what @ScottR mentioned here, you really shouldn't change the output of the query rather create states that manage these conditions in your UI.

Not aware of your exact use caser but if you just need to check if a query is empty you can use:

  {{ myQuery.data.length == 0}}

Or if your returned data is an object of arrays:

{{ formatDataAsArray(myQuery).data.length == 0}}

Hi Minijohn,

Thanks for your reply. As I mentioned I am very new to this tool, I am not sure what do you mean by states.
I'll explain what I am trying to do.
I am using Query JSON with SQL and written query and binded to grid. Till this point it is working fine.
Now I want to display "No Configuration Found" message, if there is no records in DB, to achieve that i have enabled Transformer which is below my query.
Please find below screen shot for the same, so this you will get fair idea.

I am not sure where this went wrong, it is not working - please help me to achieve this.

Thanks,
Lalitha.C

@lalitha1024, makes sense.

If you only want to display that message in your Table (grid) you can set the "Empty State" value of your table to "No configuration found". You don't need a transformer at all for this.

Check out your table component -> Data -> Empty State.

Screenshot 2022-12-06 at 14.20.30

Is that what you're looking for?

Hi Minijohn,

Thanks a lot, this works for me, we can close this issue.

Thanks,
Lalitha.C

1 Like