slysid
slysid

Reputation: 5498

Google Appscript - function could not be found

I have a simple spreadsheet bound script as below

var document = SpreadsheetApp.getActive()

function onOpen() {

  var menuEntries = [];
  menuEntries.push({name:'Archive',functionName:'startArchive'})
  document.addMenu("Custom", menuEntries)
}

function startArchive() {

  Logger.log("Will Start Archive")

}

All the script is bound to the spreadsheet.

When I reload the spreadsheet, I can see the custom dialog menu with "Archive" as it's drop-down. When I click on Archive, instead of calling "startArchive()" function, I am getting error as

script function startArchive could not be found

I have searched on similar issue but users are facing issues like this when they want to call a function from a library but not within the bound script.

I am not able to figure out why I am getting not found error for this simple function.

thank you

Upvotes: 2

Views: 7979

Answers (2)

Pedro Fajardo
Pedro Fajardo

Reputation: 51

Just ran into this, because I too had a spreadsheet bound script that was throwing the same error out of nowhere after working correctly for several days.

To solve it, I renamed the "function" that was throwing the error to something else, like "function1", saved it and it worked under the new name.

After that I changed the name of the function giving the error from "function1" back to "function", hit the save button again and voilá, the script started working again as it always had.

Upvotes: 5

Cameron Roberts
Cameron Roberts

Reputation: 7377

Your code is correct and works fine in a new sheet. I have seen similar behaviour with my own code on rare occasions, and the solution is either to wait a while, or copy the code into a new sheet and work from there.

In my experience, this issue crops up when I copy and paste an entirely new script over top of an existing script, but I have seen it occur for no clear reason at all.

My guess at the cause of this issue is that sometimes the script and the Sheet get out of sync somehow. Because Google's infrastructure is widely distributed across many servers and data centers, it makes sense that sometimes the code being executed is stored somewhere different than the code you are seeing in the editor.

Just to stress the rarity of this, I've been working with Apps Script in Google sheets at my job daily for the past 3 years, and I've seen this occur less than 10 times total.

Upvotes: 2

Related Questions