Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get data from localStorage

In my app for google spreadsheet I save some params in localStorage in one function. And in another function I need to retrieve them. Of course, I can create modeless dialog or sidebar, when will be my html code and js, but this second function only refresh current sheet, so I don't need UI. Also I know, that server side doesn't have access to localStorage.
Here is my abstract code:

server.gs:

function menuItemClicked()
{
    // when we click on item in addon menu, this called
    // and load 'client.html'
}

function refreshCurrentSheet(params)
{
    // called by 'client.html'
    // do something else with params...
}

client.html:

<script type="text/javascript">
    google.script.run.refreshCurrentSheet( localStorage.getItem('var') );
</script>

I didn't find answer in API, how to do that(

Question: how can I load html and execute js without visible UI ?

P.S. Saving these params on server-side in cache is not a solution, because I often use and change them in client

like image 587
FLighter Avatar asked Nov 20 '25 05:11

FLighter


1 Answers

You can use either Properties Service or Cache Service. Both provide localStorage functionality allowing you to store key value pairs (string type only). If you'd like to persist data between function calls, Cache is probably the best option

More on Cache Service https://developers.google.com/apps-script/reference/cache/

More on Properties Service https://developers.google.com/apps-script/reference/properties/

like image 122
Anton Dementiev Avatar answered Nov 22 '25 18:11

Anton Dementiev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!