Dynamic Resource ID defaulting to the original Resource ID

Hello everyone,

I'm trying to set the Resource Identifier for SQL-Queries dynamically to query different databases based on certain settings.
To achieve this I first create a new query to a test database and change it to use dynamic Resource Identifiers based on another resource query later on.
Now when the page loads, it sometimes initially loads the data from the test database and after a couple of seconds re-runs the query with the correct resource.
Is there any way to run a resource query with dynamic resource identifiers on page load with the correctly set resource and not to default to the original resource?
Thanks already in advance!

It’s doing that because when the page first loads, your dynamic resource ID isn’t available yet. The query engine will fall back to the static/default resource you originally set when creating the query. Once your “resource query” finishes and returns the correct ID, it re-runs the SQL query with the updated resource.

To avoid the initial hit to the test DB:

  1. Turn off Run on page load for the SQL query that depends on the dynamic resource.
  2. Run your “resource query” first on page load.
  3. In its onSuccess (or equivalent), trigger your SQL query so it runs only after the resource ID is available.

Alternatively, you can add a condition in the SQL query’s run settings so it only executes when the dynamic resource ID is set (e.g., {{ resourceId }} is not empty).