Use button/action to set temporary state initial value

Hi all.

I wanted to have a "admin" mode in on of my apps where specific user would be able to set parameters valid to everyone else. I tried doing this using temporary state variables, but for this I would have to be able to programmatically set the initial value of a state, but this doesnt seem to be possible.

Is it possible? Or do you suggest any different approach?

Thank you!


If you want to set a temp state value from a button you could use an event handler onClick that calls a js query that would return something like

// set the value to your tempStateName

return tempStateName.value

1 Like

Hi @ScottR thank you! But this would only set the current temporary value for that user, right? I want to change that temporary state's initial value, the one we usually set here in the edit mode:

Is it that you want to change the initial value based on another user and then when the admin clicks a button, the temp value is changed? Sorry but I am only aware of .setValue on the temp state and not the initial state....

I have a functionality there is controlled by a temp state. It's initial value is set and is never changed, so every user in the app always have the same value.

I want to give a specific user group the ability to programmatically change the initial value of this temp state so next time anyone loads the app it will load the new initial value.

That's the point of setting a temporary state value in what I wrote above.
The initial value would not have to be changed if you simply use the .setValue method for each user to set programmatically and take that value while the initial value can remain the same and would not be looked at by any user and only used by your application.

To give a specific user group, you can use the advanced tab here and set it to group level access depending, I think, on what version of Retool you have...

But if I use setValue the value will only update to that user, in that session. I want it to be updated to ALL users in ALL future sessions.

Makes more sense now - I think you're going to have to write to a database so that the initial value can be populated by that query the next time some one logs in who is not an admin

1 Like

yeah that was the "out of retool" option I was trying to avoid since this is for only one simple variable. But thanks a lot @ScottR

you're welcome - sorry I couldn't help more @igoraguiar - best of luck

1 Like

@igoraguiar You should be able to use a JS query to set the state of one of the global variables in the app you are in, but I am not sure if this will take affect for other uses in that specific app. Another way you could do this is to introduce a page before the one you want to influence for all users and in that page create a link that automatically sets URL parameters to the app URL so that the page has a context set on it each time someone visits the page.

Ultimately not ideal for what I think you want your UX to be, but an option that is not a database

1 Like

thank you for the suggestions @auste_rich !

You may also be able to set the default URL parameters for a page, but that might have to be manually managed rather than through a button like you are suggesting....

For instance, I have an App I wrote for my sellers that takes in an API token so that that App always syncs with my seller's personal sandbox. This is context that is User specific obviously and not global, but in the past I have just hardcoded a variable into the app since I'm the admin editor and it universally applies to whomever is using the app