0

I have some information that I would like to push from a primary google sheet to other sheets which I need to select, I would like to turn this into a menu item so I've added:

  ui.createMenu('Push to Sheet').addItem('Select Sheet', 'myFunction').addToUi();

I have a complicated function that starts with:

function myFunction(PARAM1,  PARAM2) {

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  .......

I'm not clear How to pass parameters to the function using this technique. How can I get this working?

1

2 Answers 2

4

There is no way to pass a parameter to the function associated with a menu item. Not sure why you would. Unless you have more than one menu item that uses the same function and you are trying to determine which menu item was selected. In that case you would need a wrapper function something like myFunction1(), myFunction2(), etc. linked to each menu item individually. Then within myFunction1() you call myFunction(1).

Sign up to request clarification or add additional context in comments.

3 Comments

Yes , your example is my use case. You give an example in code? I have a follow up at stackoverflow.com/questions/51826107/…
Heres is example of how to do it: stackoverflow.com/questions/51827523/…
"Not sure why you would"? Use one function to process menu items.
0

While there is no way to pass arguments to your newly created function, you can however pass in simple global variables, but they have to be defined at the root level and they cannot be altered by any means from any subsequent functions.

i.e. if you defined the following in the root script

var folderToSearch = ['folderIDString']

You could pick that up in your

newCreatedMenuFunction () {
Logger.log("folderToSearch: " + folderToSearch);
}

Output 'folderIDString'

Not that it does you much good, but some parameters are possible. You might have to rethink what it is you are trying to achieve.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.