Search code examples
google-apps-scriptgoogle-sheetsgoogle-apps

Google Apps Script Library with multiple gs Script Files not working


Relatively new to Google Apps Script.

Created a Google Apps Script file and have multiple gs files within it.

Deployed a library and included the library in a google sheet.

However, when I call any function from the google sheet, it gives an error "Script function not found:XXX"

I have created a custom menu and calling the function from there. The syntax is as follows

.addItem('Functionality','libraryname.function()') .addItem('Functionality','libraryname.function')

Help ??

When I put all the code in a single file, it works. Kind of defeats the purpose of being able to add multiple gs files and organize your code.

Have tried calling a local function which in turn will call the function in the library - that did not work either.


Solution

  • If you have a private function, probe adding an item on the menu, as follows:

    .addItem('Functionality','youFunctionName_')
    

    Notice here that the function name ends with an underscore.

    As is shown in the documentation of addItem(caption, functionName), your code looks fine, however, check the documentation about function naming for see if something else is missing in your code.

    Consider check also the rest of the documentation about custom functions and double-check that you've saved all changes made in your code, the appsscript.json file contains the permissions required (if needed) and refresh the browser for reload both the sheet and script.