'Run this query on page load' is not functioning

  1. My goal:

I’m attempting to create/add a new row to my database, then navigate to a new page. On that page I need a query to run and populate a table,which I then need use to populate with the new record previously added and selected (I use table.selectRow) so that I can continue making changes to it.

  1. Issue:

When the second page loads, the table is only is displaying the previous records, not the one I added. If i manually run the query a few times it does populate the table, but with the previous record displayed and selected and the new one displayed above it (I need the new one to be selected).

  1. Steps I've taken to troubleshoot:

I’ve attempted to set the query to run both manually and automatically, as well as select run on page load with varies delay times. I also tried turning on run periodically but that causes the same issue of displaying the new record but it’s not selected.

  1. Additional info:

I’m using the regular Retool database (PostgreSQL)

If anyone can help that would be great, I can’t see why it isn’t executing!

Hello @James_Gould!

I have a couple of thoughts that might help, but also a couple of questions.

Are the pages all setup within a single Multi-page app or are they redirecting to other app pages?

Are the queries being cached at all? You mentioned that you had to run the query “a few times” before you could see the new row data so I wonder if it is part of the issue.

Is persist row selection enabled for the table on the second page? You said that eventually the new row is present, but the wrong row ends up selected when it finally shows up. This might be related to the first question, but if you could share the code/snippet you are using for the selection method there could be something else at work there.

Hopefully something simple is causing the problem since it seems like what you are trying should already be working to some extent.

Hi @pyrrho

The app is Multi-page, I’m not redirecting to another app page.

I’ve tried turning on caching but i’m still seeing the same issue.

https://www.icloud.com/iclouddrive/09a8jRVdqMy2a7It4ZMUpum7Q#Table_Not_Updating

One thing to note is that the database doesn’t seem to update until I click on the window.

I didn’t have persist row enabled, but I just tried that and the is issue is still occurring :frowning:

Hey @James_Gould - the exact explanation is highly dependent on how you currently have everything configured, but I'm guessing that you're navigating to the second page before the new data is technically persisted in the underlying database. Alternatively, it's possible that you are explicitly disabling the query under certain conditions.

It would probably be most efficient to take a look at this during Office Hours, if the timing works for you! If not, you can try sharing a JSON export of your app. :+1:

Ah, I think i’ve found a work around, if I execute the query after the submission but before the navigation it seems to work, the table on the second page loads and displays the correct record when it loads.

This must mean that the database DOES have the new record stored, but since the run on page load seems for me at least.

For now I think i’m satisfied with my workaround.

Thank you for pointing me in the right direction! :slightly_smiling_face:

1 Like