Reputation: 23
In my google appscripts web app, I have a variable defined in the client (js) file. Let's call that variable qty. I need that variable in a number of server functions, so currently I'm doing this:
<script>
google.script.run.serverFunction(qty);
</script>
And my server script looks like this:
function serverFunction(qty) {
...
INSERT INTO table (blah) VALUES (qty);
...
}
But instead, I want to pass qty to server once, set it as a global variable (?) ... so that I can use it directly in all my server functions and not have to pass it from the client every time.
Why do I need this?
Because currently, a savvy user can run google.script.run.serverFunction(qty);
in the console and INSERT random things. Figure if the input variable is set in server, there's more control.
Upvotes: 2
Views: 307
Reputation: 31300
You will need to use:
PropertiesService.getScriptProperties()
and put the data into the Properties Service. However, one property can only hold 9k of data. If your data is over 9k, you'll need to split it up. If it's a lot more than 9k, like 100k, then it might not work to put data into the Properties Service. If you only need to hold the data for less than 6 hours, you can use Cache Service, and store up to 100k in one property.
Apps Script Documentation - Cache Service
Upvotes: 2