0

I have found the code:

var strings = {};
strings["Item1"] = {'func':"function1",'arg':"yes"};
strings["Item2"] = {'func':"function2",'arg':"no"};
strings["Item3"] = {'func':"function3",'arg':"maybe"};

Object.keys(strings).forEach(function (name) {
  this[strings[name]['func']] = function () {
  myGatewayFunction(strings[name]['arg']);
  }
});

function onOpen() {
  var ui = SpreadsheetApp.getUi()
  var myMenu = ui.createMenu('Spezial');

Object.keys(strings).forEach(function (name) {
  myMenu.addItem(name,strings[name]['func'])
});

  myMenu.addToUi();
}

function myGatewayFunction(arg){
  SpreadsheetApp.getUi().alert(arg);
}

I found this code here and it works as it should. Many thanks to the author, which I now unfortunately no longer know. But I need it a little bit different. In a column 1 in a hidden table is the name of the menu item. When I click on the menu item a function should be called which gets the name of the menu item as parameter. In the function myGatewayFunction(arg) I can write my actual code. But how do I get the above code to not use the var string.... but to take the values from column 1 ? My knowledge in google script is not so good yet. I come from the vb-corner and have to switch to googlescript because of my job. I would be grateful for any help. To learn the whole thing I always pick apart any working code and try to understand it that way.

nonPro
  • 1

0 Answers0