I have two Apps Script Code.gs and Code2.gs
I would like to import function A in Code2.gs and use it in function B in Code.gs.
Any ideas ?
I have two Apps Script Code.gs and Code2.gs
I would like to import function A in Code2.gs and use it in function B in Code.gs.
Any ideas ?
If both gs are in the same project, its already available. Else read about apps script libraries.
gs
files matters appears to have changed (possibly more than once). As of June 2022 release notes: "Now, the order of files in the Apps Script editor doesn't matter. " developers.google.com/apps-script/releases#june_2022 –
Neurology Import is not needed. And
As of June 2022 release notes: "Now, the order of files in the Apps Script editor doesn't matter. "
Thanks to @pestophagous 's input
Put the function-defined-here.gs
before function-used-here.gs
in the list on the left, and call the function. The order DOES matter.
In addition to the answer from @Zig Mandel
If both gs are in the same project, its already available. Else read about apps script libraries.
Files in the same project are executed by order in the list (in the new editor you can change the order) like importing a bunch of javascript with <script>
tag into an HTML. So you will almost ways want the Code.gs
be the last one in the list (the most dependent one). Also, names are irrelevant since all callback functions are added to the namespace, and later being called by the name from manifest file.
Fact: I searched the document about the fact I mentioned and it is not mentioned anywhere. I myself have decided stop using GAS for this fact, and these reasons for myself.
gs
files matters appears to have changed (possibly more than once). As of June 2022 release notes: "Now, the order of files in the Apps Script editor doesn't matter. " developers.google.com/apps-script/releases#june_2022 –
Neurology "If both gs are in the same project, its already available"
Yes, BUT you need to name the functions correctly. The name of the function with a capital letter determines its availability. "MyFunction" will be available in all .gs files of the project, but "myFunction" will NOT be available in other files.
© 2022 - 2024 — McMap. All rights reserved.