Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Script Function not found

Here is my code. Ir runs fine from Debug and from Run in the code ui, but when running from the press of a custom menu button I get this error:

Script function not found: function menuItem1() { var ui = SpreadsheetApp.getUi(); ui.alert("Hello There"); }

Here is my code:

function menuItem1(){
 var ui = SpreadsheetApp.getUi();
   ui.alert('Hello There');
}

That is it!

I have other sheets that have tons of code that do all kinds of craziness with spreadsheets and and even form creation.

Cant figure out why I am getting this. It doesn't matter code I put into this function either. I get a listing of the entire code in an error detail form presented as a dialog over the spreadsheet.

Anyone?

like image 590
akitaguy Avatar asked Nov 17 '25 19:11

akitaguy


1 Answers

What a dummy I am. Must be staring at the screen too long!

The code was fine. It was the creating of the custom menu item that was BROKE!!

function myFunction() {
  var ui =  SpreadsheetApp.getUi();
    ui.createMenu('League Wheelhouse Menu')
    .addItem('Create League Forms',  'menuItem1')
    .addToUi();
}

I forgot to ' ' around the name of the function. Of course my code is tons longer than the code above, but since it was throwing this crazy error I decided to replace the code with something crazy easy to try and find the issue.

Could not find it with crazy easy so I started a new project. When I created the menu creator I put the ' ' around the function name as I typed. BAMM... SLAM... KAPOW... that is when it hit me.

I bit surprised that when you save the file it does not throw a compiling error.

All fixed.... so dont forget when you put in a custom menu item.. put your name in AS TEXT!!! 'HappyProgramming'

like image 75
akitaguy Avatar answered Nov 19 '25 09:11

akitaguy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!