Variable scoping

Hello all,
Can someone tell me the rules for variable scoping?

Specifically, I know I can declare and use local variables inside an event handler (Javascript), but how do I declare and reference an application-global variable?

As a use case, I want to read the assigned primary key value from the result object of an insert query, then persist and use that value in various ways without always looking back at the query result, which will change when the query is triggered again. How do I create a globally-scoped variable that I can access from down inside event handlers and other scripts? I've searched the docs to no avail.

Thanks in advance,
Edward

Variables are created in the code panel of your retool app - these are available within your app and your current session - ie they're lost if you navigate to a different app and they're only available to that user/session. eg {{myVariable.value}} exists only on that app/page

Configuration Variables - these are set in your retool advanced settings page and are best used for global settings for all users across all apps and probably have limited use and shouldn't change much. eg {{retoolContext.configVars.myGlobalVariable}}

localStorage - a browser based data set that persists between sessions and, again, probably has limited use cases but is handy for things like offline data stores

I would suggest that based on your use case a standard variable in your retool app would be perfectly valid, ie a variable called "last_saved_id" which you can set the value of in the success event handler of your save function. This would be available anywhere within your app until the next save overwrites its value. It's the same as going back to the query results but its much easier to read.

Thanks so much. Exactly the clarification I needed.