Runs the query and send an email if the query returns a result

hi people,

i want to catch some not allowed actions. based on that i have a query which normally returns null. but if the rule is broken, then my query will give not null.
based on that scenario i want to build a tool to run query automatically and if it returns anything than null, the app will send an email to assigned person. can you guys please help me?

best regards.

Hi there @halil,

This is quite easy to achieve. Are you comfortable with using Retool's email resource for the email, or are you using your own resource for that?

In any case, you can set up a success event handler in your query that runs only when there is data returned, e.g.

This will trigger your email query, where you can put all of the logic for who is the assigned person, what text, etc.

1 Like

Many thanks @MiguelOrtiz,

i have some problems like following ones;

  1. i need to attach the result of query or table component in email as attachment, do you have an idea, how to get that?
    image

  2. i need to run that query at 10 am and 4pm everyday. I need to schedule my query.

  3. is it possible to compare the result number with the day before. so based on compare result i can decide to send the email.

Hi @halil,

I think workflows are more apt for what you're trying to achieve.

You can create a document by transforming your query data to base 64 and the compare your results to the ones for the previous day and create a branch to decide whether the email is sent or not.

Here are two screenshots that can guide you on how to start>

  1. Schedule your workflow

  1. Build your blocks with your logic (I have titled the blocks in a way that kind of fits your user case, just to give you the idea)

On each block you can reference any data from previous blocks, so you can build your compare to last day logic easily.

Hope this helps!

1 Like