Using built-in objects in Query Library

  • Goal: I want to use retool objects in a centralised query in query library like retoolContext or current_user

  • Steps: In the query library, create a query where you reference {{ current_user.email }} or {{ retoolContext.appUuid }}. Then go to an app, then select the query from the resource "Import from Query Library", and run the query without having to populate the variables from the app.

  • Details: When I set up the shared query as in the screenshot, and then access this query in an app, and leave the fields unpopulated (as I expected them to pull automatically from inside the shared query when it runs), it reads those values as undefined instead of actually accessing them from inside the query in query library. In the app, I get the error for example:

"{{ current_user.id }}" was evaluated as undefined, which did not match the value expected.

I would assume this is because the functionality to do this does not exist, and you would have to pass the value in at the app level when you hit the query. Ideally I would like to centralise these values so that you don't need to put them in for every time you use the query in each app.

I believe a similar question was asked here but this was 2 years ago and it was mentioned that it's on the radar.

FYI - I am using self-hosted Retool.

Thanks!

Hello @Reynard_Marx!

Let me see if I can help you out with this.

I just did some testing and I can confirm that the query library currently does not have access to global or app specific variables in the QL editor.

It seem that the Variables input field on the right side of the QL page only takes hard coded values as strings and is not able to interpolate variables from JS in double curlies.

I can definitely make a feature request to see if this input field can be modified to accept commonly used global scoped objects such as retoolContext and current_user when creating the query in the QL.

In the meantime, the best work around would be to add in the JS interpolation in the app. I understand this is not ideal and can be tedious when using a query in many apps, but it will reliably work as needed and allows for greater specificity if needed down the road.

Thanks @Jack_T , yes that's the solution I went with. If we were able to accept global scoped objects in a shared query it will be a great addition!

1 Like

Great to hear!

Will keep you updated on the ticket with any news I hear from the eng team on adding in the functionality for globally scoped objects in the QL!