Ok, I feel embarrassed that I wasn't able to figure this out on my own, but after a few wasted hours, I figured it would be easier to simply ask over here:
I have a bunch of .gs-files in my Google Apps Script project. Now, I want to call another file's function from a method (something like AnotherClass.awesomeFunction()
, which throws a ReferenceError
though). Is this possible in Google Apps Script? If so, how?
The following syntax allows you to call any function from within your Google Apps Script project, regardless of whether the function is defined in the same file that is calling it:
The following code is unnecessary and will throw errors:
Files aren't classes. You can call any functions in any file from any other file. Think of your files as if they were just added together before running. If you want class-like scoping you can use the Libraries feature.
It can do.
and Corey is right, files is not class.
Please see below code:
https://script.google.com/d/1QcyrlnwWGdMnJNxJ2X4qfGeM1q75YxJopPuNKUDgOjmqsp4dilLYtC-A/edit