Running SQL Query and then download that data

Hi Retool Community,

I have an application that generally allows users to see data and then download data.

The current workflow is as follows:

  1. User builds their query
  2. User sees the truncated data (limit 1000) in a table
  3. User investigates to confirm its the data they need
  4. User downloads non-truncated data (limit removed)

The table seen below is the truncated data. The download data button has two event handlers, run_the_full_query.trigger() and export the data from run_the_full_query.data. However, because the event handlers are run in parallel, the behavior is buggy. Often times, the export is completed before run_the_full_query.data is populated resulting in an empty file.

It is my understanding that I need to an javascript query to make an async call but am not proficient in javascript. Has anyone developed a solution similar to this / have any advice on JS syntax for this problem statement?

This question is related to this post: manage-execution-order-of-event-handlers

Thanks in advance!

Can you share your run_full_query?

You can add an export trigger on its success handler.

2 Likes

Hi @edurmush, thanks for getting back to me. Your solution does work.

I also was able to develop another solution using this retool community post where the download data button triggers the download_data_query (a JS query) which runs the full_query (a SQL query) and then exports the data on success

3 Likes