Specify parameters for menu functions

前端 未结 1 520
生来不讨喜
生来不讨喜 2020-12-20 21:46

This is a snippet in the Google Apps Script for adding a menu in Google Docs/Forms/Sheets. As stated in the Menu#addItem method it calls the menuItem2

相关标签:
1条回答
  • 2020-12-20 22:38

    You can't add parameters to functions called by a menu.

    A simple workaround is to store parameters elsewhere (in scriptProperties for example) and read these parameters if parameter is undefined.

    function menuItem2(PARAMETER) {
      // if PARAMETER is undefined then read default parameter in scriptProperties
      // codes    
    }
    

    In this configuration you can call the menuItem2 function from elsewhere in the script using a "normal" parameter and it will be handled as expected.

    0 讨论(0)
提交回复
热议问题