Dynamically set retoolContext.environment

I'm trying to build a workflow that will loop through my environments (e.g. const envs = ['dev', 'stage', 'prod']) , update the current environment each loop, and then perform a resource query.

So for example, on the first loop, it will run the query for dev, then for stage, then for prod.

The idea is eventually I'll merge all of the data into a single result set and output to CSV.

Is this possible? I can't seem to figure out a way to dynamically set the current environment programatically.

I don't think you could do that - environments are typically (and I assume in Retool's case too) totally separate from each other. You aren't meant to connect to a dev database from prod, or anything like that.

What you might be able to try though, would be to set up a webhook for each environment and have the workflow respond with the data you want from the env. Then call each webhook from Prod, assemble the data, and do whatever you want with it.

Hey Mike,

The environment array was a bad example. These are all production environments, as we run single tenancy databases separately.

What I'm trying to achieve, is running the same query across all our production databases and merging the data.

If I could set the retool environment dynamically, I think this would be a neat approach.

The alternative is to setup X different postgres resources pointing to each different production database, which I really don't want to do.

Hey @melloyellow, I don't believe being able to programmatically change the retoolContext.environment is on the roadmap, but I've submitted the request for you. As you mentioned, the workaround would be to set each postgres db to it's own resource.

Is there a way to set the environment on startup. I want our users to go to the production environment regardless which one they had selected from before.

@Tamas_Juhasz you can append _environment=production to the app url. Docs here, which forces the app to load in the specified environment.

Thank you.

I think it'd be useful for single tenancy applications, where we're reporting against multiple databases.

Thanks, @melloyellow I'll pass that feedback along.