6
votes

I've followed the instructions from: https://developers.google.com/apps-script/execution_custom_functions to create a custom function.

Neither my functions or even cut and paste from the tutorial works: the functions aren't available to my spreadsheets. I've tried saving a version and publishing as a web app - with no change. I tried Google Chrome and Firefox, same result. Am I missing something really obvious here?

3
have you tried to run it once using the 'run' command in the script editor ? (you don't need to publish nor make version when using custom functions)Serge insas
Did you write the script from within your spreadsheet or as a standalone script ? You should write it within your spreadsheet. Also, as Serge mentioned, you should run it from the script editor once so that any authorization necessary can be provided.Srik
When I run the script, it executes top to bottom, going straight into functions without me calling them. This fails because arguments were never passed into the function(s). If the code was: function doStuff(arg1, arg2) { if (typeof arg1 != "number") { throw "arg1 must be a number"; } var out = 1 + 1; return out; } it would fail on the throw line. This doesn't make sense to me because I never actually called the function.Justin Tilson
The lights are coming on (slowly). I found the dropdown which lists the function you want to run or debug. This explains why a function is getting called. It still doesn't give me a chance to pass in arguments (that I can see). It is possible to pass arguments into functions through either the run or debug menus?Justin Tilson
or maybe just refresh the spreadsheet and try again :-)ralixyle

3 Answers

10
votes

You need to have a comment with @customfunction in it above your custom function. Google Sheets will then add you custom function to the autocomplete menu.

2
votes

Not sure if this is what you ran into...but what happened to me is, I didn't see my custom function in auto-complete and I thought it's not working. But if you just type =double(A1) in a cell (using the official example, assuming there is something in A1...), it will compute!

0
votes

Does your Chrome Popup setting determine whether the customFunction autocompletes when you enter in in a cell? If so how would you add it as an allowed exception in settings? Enable autocomplete is checked under the tools menu in the spreadsheet.

My function works fine if run from the script editor but does not autocomplete when =myCustomFunction or =myCustomFunction( entered in a cell.