Dynamic Resource Switching in Retool

Hi Retool Support Team,

We're currently using the Retool Business plan and have a requirement regarding resource management in our applications. We need to dynamically switch between production and staging resources in our Apps.

We've noticed the toggle at the bottom of the screen for switching environments. However, switching the environment doesn't automatically switch the resource to the corresponding production or staging resource.

Could you clarify how to configure Retool to automatically switch resources when changing environments? If this isn't supported, could you suggest any workarounds or best practices?

Thank you for your help. Looking forward to your response.

Best,
Laman

1 Like

hey @leman and welcome!

looks like others this year are wanting this too:

apparently you can set the environment via _environment URL parameter for the app: Customize app URLs | Retool Docs

maybe you can have multiple queries -- one for each environment -- and conditionally trigger or reference their data in JS? as in, you could create a resource for your database (or whatever) for each environment and then do:

let data = {}
const env = retoolContext.environment

function triggerQueryGetData(query) {
    await query.trigger({additionalScope: {}})
    return query.data
}

if (env == "staging") {
    return triggerQueryGetData(queryStaging)
} else if (env == "production") {
     return triggerQueryGetData(queryProduction)
}
console.error(`no query assigned to environment "${env}"`)

it's not the most maintainable, but it sounds like retool might consider adding it soon. I know there's been a lot of discussion and requests surrounding environments this year, so I'm hopeful too.