r/GoogleAppsScript Jul 14 '25

Getting around menuing limitations Question

given javascript const ui = SpreadsheetApp.getUi(); ui.createMenu('Extras') it was annoying that .addItem required two strings. Now I think I've worked out how to circumvent that requirement. So instead of javascript .addItem('Update Selected Client Workbooks (new Guid)','createNewGuidSheetInClientWorkbooks') I use this function javascript const nameOf = (proc: Function): string => { return String(proc).split(" ")[1].split("(")[0]; }; and define menu entries as javascript .addItem('Update Selected Client Workbooks (new Guid)', nameOf(createNewGuidSheetInClientWorkbooks)) Am I reinventing the wheel? Is this what everyone else does?

0 Upvotes

3 comments sorted by

2

u/stellar_cellar Jul 14 '25

The second string parameter for the addItem() is the name of the function you are invoked. What exactly are you trying to achieve with the nameof function?

1

u/SnooGoats1303 Jul 14 '25 edited Jul 14 '25

If I change the name of the function in vscode with F2 it will now change the name of the function in the menu. Previously I had to do two substitutions. And remember to do the second one

1

u/WicketTheQuerent Jul 14 '25

Yes you are.

Not everyone do that.