Can a Google Sheets custom menu pass a variable to function?

后端 未结 3 1093
失恋的感觉
失恋的感觉 2020-12-17 01:24

I\'m creating a menu item in Google Sheets that will list a work directory and pull the email address for that user, to be later used to process employee records within Goog

3条回答
  •  一个人的身影
    2020-12-17 02:12

    When you create a menu item with

    .addItem('Nathaniel MacIver', menuItem2('nm@emailaddress.com'))
    

    the function menuItem2 is called with the parameter 'nm@emailaddress.com'. This results in the alert that you see. The return value of the function is undefined (as you don't return anything from it). So you end up with the same menu item as if it was

    .addItem('Nathaniel MacIver', undefined)
    

    which clearly isn't going to do anything.

    The method addItem takes only a function name, it does not allow for passing parameters to that function. To do what you want, you'll need separate functions for each person, each with an email hardcoded inside that function.

提交回复
热议问题