Google Sheets - Script function could not be found
Asked Answered
A

12

12

I am working to link an image in my Google Sheet document to a specific cell in another tab. I'm doing this by building a simple function that will do this. However, when I assign the function and then click on the image, I then get the error "Script function "test" could not be found". When I run the function in the script manager interface, it works fine. It's when I try to actually use it in the sheet with the image.

Function Script:

function test()
{
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName("TX Marketing Data");
  sheet.setActiveRange(sheet.getRange("A91"));
};

enter image description here

Steps to recreate:
1) Create image
2) Go to image, right click, go to drop down and select "Assign Script"
3) Enter "test" as the assign script

Angers answered 19/5, 2016 at 21:32 Comment(5)
Double check that there isn't a typo in the script name. I followed your instructions and used the same code. It worked just fine.Kampala
No typos. I can't believe it's working for you! I still can't get it to go :/Angers
Here is my file: docs.google.com/spreadsheets/d/…Kampala
Thanks, Ruben. This helped to spark an idea. I believe it's not finding the function because I am not the owner of the sheet.Angers
I've had this same issue and it turned out that the document owner had left their job and ownership rights had been moved to someone else. I'm not sure why this would matter, but we're using BigQuery so maybe this new owner doesn't have permissions or something, but yea that could be the issueButanol
G
5

Had a similar problem and just solved it.

When assigning a script function to a button make sure to call the specific function name(i.e. "getWeatherData") and not the App Script name (i.e. "WeatherAPI").

Gameness answered 12/2, 2021 at 14:51 Comment(1)
Also make sure you do getWeatherData instead of getWeatherData(). This was my problem!Occasional
S
4

Remove ";" at the end of your function (after }).

Suspension answered 20/5, 2016 at 6:25 Comment(0)
C
4

Another thing that can happen is that you have a library that has the same name as the function. For example you have imported a library that to refer to "test" in your code. If you name your function

function test(){
   your code
}

Then you will get the same error that you got. visual example of library with same name of a function

Countermand answered 19/8, 2021 at 19:44 Comment(0)
M
3

Try reloading the page.

Sounds like a simple 'turn it off and on again' fix but after having the same issue and trying to save a new version, renaming the function, creating new function etc. a page reload was all it took!

Maleeny answered 27/3, 2018 at 13:39 Comment(1)
Doh!!! This worked for me. After assigning the function to the button, the page needed a reload to work. Before that it gave the "Script function xxx could not be found" error.Hjerpe
S
1

You should call your function name, not the script itself. If your function is called myFunction() you should write myFunction. And be careful to rename your function to something that isn't already in your library

Sobriquet answered 28/1, 2022 at 11:53 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Chaing
E
1

Ran into the same issue but solved it by renaming it with a prefix, executing it in Sheets and then renaming it back without the prefix.

function calculateSomething() {
  return 10;
}

To

function prefixCalculateSomething() {
  return 10;
}

Update the Sheet with the new name, it should work now. Now rename it back.

function calculateSomething() {
  return 10;
}

Update the Sheet with the original name, and it should still work. Maybe a refresh would've worked as well but that's not how I solved it.

Evocator answered 7/5, 2022 at 2:24 Comment(1)
This worked for me. Out of the blue just happened. All the scripts were displaying the same error "not found". I renamed only one of them, assigned it to the button, it worked along with all the others which were untouched. Thank you Nate.Hudgens
R
0

I had exactly the same problem. Eventually I found the problem when I looked at the script Function name, which should be Function followed by the name you gave the script when it was created. when creating file names sometimes you are not able to use special characters which is what I had done. Once I gave it a name that had allowable characters there was no problem. In programming when you call a function that does not match the name given to the function or procedure you will end up getting the error function not found.

Romeo answered 14/12, 2020 at 4:25 Comment(0)
L
0

Same issue, but much dumber reason for me.

So, here is my answer: Make sure to hit the "Save" button in Apps Script.

I was so used to all the other google apps automatically saving/syncing I didn't realize that I actually had to hit "Save" on the scripts. I caught it when I noticed the function I was trying to run wasn't appearing in the list of functions to run in Apps Script. Once it hit save, the name of the function appeared in the list AND clicking my button ran it successfully from the sheet.

Lutz answered 20/1, 2022 at 16:4 Comment(0)
R
0

I found that I had renamed my Macro, removed spaces, and added Uppercase, but the name in the script function statement didn't match what I could swear I had set in "Extensions->Macros->Manage Macros". When I changed the syntax of the image to match the function statement, including case, it worked fine. (I don't know if spaces work in the name, I originally had them, but remembered that I've had trouble with them in Excel. I removed them at the same time as doing other changes, so I didn't confirm if it was an issue.)

Rutger answered 30/10, 2022 at 22:46 Comment(0)
F
0

Having had the same issue when clicking a button, what fixed the problem for me was removing spaces from the macro name that was being assigned, despite the fact that it worked fine with spaces when using the hot keys assigned to it.

Fumarole answered 30/3, 2023 at 13:23 Comment(0)
C
-1

I had the exact same issue, when I used submitdata , after I changed it to submitData it said it submitdata was deleted. so i put it back to original form and bam!! fixed.

Cineaste answered 6/8, 2021 at 10:39 Comment(0)
F
-1

I had the same issue. I had left in the brackets (parenthesis) when assigning the script to the button. Took those out and it worked fine.

Frae answered 7/6, 2023 at 11:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.