0

This is a minimum working example to illustrate a problem I'm facing. I'm just a beginner, so any help is appreciated. I received an error message that says Script function not found: sum(1,2). Can someone please tell me what's wrong with my code?

function onOpen() {
  var ui = SpreadsheetApp.getUi();
  ui.createMenu('Sum of two numbers')
      .addItem('Example 1', 'sum(1,2)')
      .addItem('Example 2', 'sum(2,3)')
      .addToUi();
}

function sum(a, b) {
  var total = a + b;
  return total;
}
emnha
  • 383
  • 1
  • 4
  • 14
  • 1
    You cannot add parameters to a function name in a menu. – Cooper Apr 30 '23 at 03:38
  • Maybe useful: https://stackoverflow.com/questions/64383424 – TheMaster Apr 30 '23 at 07:34
  • Do you really need to send the parameters to the function from the button or are you ok with the function reading it from somewhere else, for example a specific cell? I think understanding your full use case may give us more info to help you find a solution. – Fernando Lara May 01 '23 at 15:35

0 Answers0