I have a script that I use as a library loading it in the spreadsheets I need.
When I add it to a spreadsheet, I define an onEdit and onLoad function that are calling the library’s corresponding methods.
I need my individual sheets that are using the library, to define a global variable that should be available to the library, that variable may not be set in a sheet’s cell.
I tried setting
var previd = "myid";
at the beginning of the spreadsheet script but that doesn’t seem to do the trick.
How may I solve that ?
The “global scope” is not shared between scripts, it is actually a “script scope”.
All variables needed for your library functions must be passed as parameters to these functions. If you make many functions call with the same parameters you should consider wrapping them in an
object. Like some Apps Script built-in functions haveoptArguments.You may also have a
setParametersfunction on your library to pass these variables once (per runtime) and have them available to next library calls. Something like this: