0

Please forgive me if I am not explaining something correctly. I have been using MS Office VBA for the past 15 years and I am just now trying to switch over to Google Apps Script.

I am using some code that has global variables set. After I got the first part of what I was trying to do to work, I added a function for when I edit my sheet. The code I found as an example started with function onEdit(event).

Initially, this function didn't work, but I found that if I removed the global variables I used with the previous function, the function onEdit(event) worked. Why would global variables prevent other functions from running? I made sure that there were none of those set variables in the function onEdit(event) code, so I would think it wouldn't interfere with that code.

  • 3
    Whenever any function is called, all global variables are loaded before the function starts. If however, you don't have enough privileges to load a specific global variable (especially in the case of **simple** edit trigger), the runtime crashes with insufficient permissions. Don't use global variables or use them for simple strings/number declarations-not to call a service that requires authorization/permissions. – TheMaster Nov 17 '19 at 05:55
  • 3
    Does this answer your question? [Using Global vars in GAS, is it advisable? are there any downsides?](https://stackoverflow.com/questions/30013661/using-global-vars-in-gas-is-it-advisable-are-there-any-downsides) – Rubén Nov 17 '19 at 06:15

0 Answers0