Based on Adding arguments to a function in the onOpen entries object , I'm trying to add entries to the menu of a google sheet.
I'm getting The error in the title:
Script function not found: entries For more information, see
https://developers.google.com/apps-script/refere
What am I doing wrong in my code below?
function onOpen() {
var ui = SpreadsheetApp.getUi();
var entries = [{
name : "Summary",
functionName : "copyRowsByColumnPattern",
},
{
name : "Summary2",
functionName : "copyRowsByColumnPattern",
}];
ui.createMenu('Push to Sheet').addItem('Select Sheet', 'entries').addToUi();
}
The problem is
.addItem('Select Sheet', 'entries').addToUi();
, you're passing the string entries as the second argument instead of the objectentries
.Just change that to
and it should work.
Actually, if you want to add multiple items at once, you need to use
addMenu
So, it should be:
addMenu('Select Sheet', entries)
To create a menu, as indicated by the Apps Script Menus guide, there are two routes:
Ui
class (for Docs, Forms, and new-version SheetsSpreadsheet#addMenu()
(for old-version Sheets).Given a set of parameterless functions to run:
With the
Ui
route, you can only add items one-by-one:This approach allows defining separators and sub-menus as well, hence the one-by-one nature.
The
Spreadsheet#addMenu
syntax allows direct initialization:Both routes require your Script Project to have defined
foo()
,bar()
, andbaz()
prior to theMenu
creation.Note also that the Apps Script server is not persistent - if you define those functions programmatically in
onOpen
, they cease to be defined once the script has finished running, and would need to be redefined every time before they could be accessed.The easiest way to create a menu is as follows:
Documentation