AndrewT
AndrewT

Reputation: 498

Alternative to global variables

Hi I am doing a simple script where I want to track what step I am up to and use the result from a button click handler. 1)I cannot pass the variable as it is an event 2)Cannot use global variables as they seem to be constants only once set Is there any way to set and object or variable multiple times and access the current value from within a handler function?

Found several examples suggesting a hidden widget, as well as that being a poor solution I also struggled to retrieve the value once set. IE it had a .setValue but no .getValue

Help please this is not a difficult thing in any other language I have tried but new to GAS

Cheers

Upvotes: 0

Views: 222

Answers (2)

DavidF
DavidF

Reputation: 1345

Private Cache is intended for this type of thing https://developers.google.com/apps-script/reference/cache/

Upvotes: 0

Srik
Srik

Reputation: 7957

There are more options - one, as you mentioned is to use a hidden widget. Although there is no .getValue(), it can be accessed through e.parameter within the click handler.

Two, for small amounts of data, you can use ScriptProperties / UserProperties and CacheService

Third, you can use the script DB or a spreadsheet if you are dealing with large amounts of data. Having said all this, it would be better if you can post some code of what you're trying to achieve. Many times, code speaks louder than words.

Upvotes: 2

Related Questions