Home>

Because the GAS code I'm currently writing has become long, I want to divide some functions into separate files.
So I tried following qiita article , but I couldn't.

Specifically,
I want to call the functionreply (~);inmain.gs,
function reply (~~~) {...}is described inreply.gs.
But when I try to runmain.gs

  

"reply" is not defined.

The error

occurs.
I do not think that I can call it simply by "describe the function in another file in the same folder" (it is not actually good), but what kind of procedure will you be able to call? .

Thanks for your professor.

  • Answer # 1

    Since I am a beginner, it may be wrong, but shouldn't you use something called "library"? It looks like an import like python or Java.
    [GAS ​​for beginners] Let's leave troublesome things to the library! Overview and how to add it

      

    GAS provides a mechanism that allows you to use the functions you create from other projects. This is called a library.

    Is this all right?

  • Answer # 2

      

    I don't think I can call it just by "describe the function in another file in the same folder"

    No, you can call it.
    Please create two files as follows.
    If you executemain (), you can see that the log is output.
    First, let's check if the function name is typo.

    main.gs

    function main () {
      reply ("Called reply.");
    }

    reply.js

    function reply (value) {
      Logger.log ("value =" + value);
    }

Related articles