I am testing the use of libraries for a first project I want to run in Google Sheets. I created a Google Sheet, with just a single button (a drawing) in it. To this button, I assigned my script ‘myFunction’.
This ‘myFunction’
- Calls ‘justMyTestFunction’ in library Tlib
- Logs a locally defined constant string (logInfo) to the Logger
- Logs a string, defined in library Tlib, to the Logger
Below you see the content of my Google Sheet Script
const logInfo = 'This is a local sentence; not stored in any library';
function myFunction() {
TLib.justMyTestFunction();
Logger.log(logInfo);
Logger.log(TLib.logSentence);
}
And you see the content of my Tlib library
const logSentence = 'This sentence is stored as a constant in library TestLibrary...';
function justMyTestFunction() {
Logger.log('This sentence is hardcoded in function justMyTestFunction of library Tlib...');
}
When clicking the button in my Google sheet, the result is the following Logger information:
Stackdriver-logboeken
31 aug. 2020 22:11:25 Informatie This sentence is hardcoded in function justMyTestFunction of library Tlib...
31 aug. 2020 22:11:25 Informatie This is a local sentence; not stored in any library
31 aug. 2020 22:11:25 Informatie null
From which I conclude:
- The call to ‘justMyTestFunction’ in library Tlib was successful
- The access to the locally defined string was successful and could be logged (of course )
- The access to the string defined in the library (Tlib.logSentence) was not successful. As a result, the null value is sent to the Logger
What I cannot understand : apparently the link with the library is OK, because my Sheet can access and execute the function ‘justMyTestFunction’. But the same Sheet has no access to a ‘global’ constant, that was defined in this library. Obviously I am missing something trivial here. But I am ‘out of ideas’. Can anyone point me to the cause of the problem and its solution ?
Thanks a lot!