1

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’

  1. Calls ‘justMyTestFunction’ in library Tlib
  2. Logs a locally defined constant string (logInfo) to the Logger
  3. 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:

  1. The call to ‘justMyTestFunction’ in library Tlib was successful
  2. The access to the locally defined string was successful and could be logged (of course )
  3. 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!

Tanaike
  • 181,128
  • 11
  • 97
  • 165
SEPport
  • 11
  • 2

1 Answers1

0

It seems that in the current stage, when const is used in the library as the global variable, the value cannot be retrieved from the client. I think that this might be resolved in the future update. So as the current workaround, please use var instead of const as follows.

From:

const logInfo = 'This is a local sentence; not stored in any library';

To:

var logInfo = 'This is a local sentence; not stored in any library';

After above modification, please test it again. When the developer mode of the installed library is "ON", you will be able to test the modified script.

Reference:

Tanaike
  • 181,128
  • 11
  • 97
  • 165
  • Hello Tanaike, thanks a lot for your prompt reply! I will surely test it, and come back with my findings. – SEPport Aug 31 '20 at 22:41
  • Changing `const` to `var` solved the issue perfectly. Thanks! This is a solid workaround until the issue is taken care of in one of the future updates. – SEPport Sep 01 '20 at 07:18