Issue with creating custom menus

180 views
Skip to first unread message

James Schmurr

unread,
Apr 8, 2020, 3:31:16 PM4/8/20
to Google Apps Script Community
There was an attempt to create a quiz.
ui.createMenu('Minigames')
      .addItem('Quiz', 'quiz1')
      .addToUi();
A snippet of code that creates the quiz starter.
function quiz1() {
  DocumentApp.getUi()
      .alert('Question 1 goes here')
  var ui = DocumentApp.getUi();
  ui.createMenu('Quiz')
      .addItem('Read question again', 'question1')
      .addSubMenu(ui.createMenu('Question 1'))
          .addItem('ans1', 'quizWrong')
          .addItem('ans2', 'quizRight1')
          .addItem('ans3', 'quizWrong')
      .addToUi();
}
Another snippet outlining the quiz dropdown itself.

For some reason, running the quiz1 function returns the exception "Custom menus must contain at least one item".
Can anyone help with this?

Alex

unread,
Apr 9, 2020, 4:42:47 AM4/9/20
to Google Apps Script Community
Hi James!

Your submenu doesn't have an item. Try this

function quiz1() {
 
DocumentApp.getUi()
 
.alert('Question 1 goes here')
 
var ui = DocumentApp.getUi();
  ui
.createMenu('Quiz')
 
.addItem('Read question again', 'question1')

 
.addSubMenu(ui.createMenu('Question 1').addItem('HERE!', 'fnHERE')) // <= For James

 
.addItem('ans1', 'quizWrong')
 
.addItem('ans2', 'quizRight1')
 
.addItem('ans3', 'quizWrong')
 
.addToUi();
}

Best, Alex.

James Schmurr

unread,
Apr 9, 2020, 12:38:38 PM4/9/20
to Google Apps Script Community
Thanks Alex!
Reply all
Reply to author
Forward
0 new messages