My script cannot be used in Google App Script V8 model, because there is a problem that causes triggers that are created automatically via script to crash.
So I need to use Legacy Mode, old version of GAS.
I'm trying to adjust the script so that a Menu is created in the spreadsheet, containing all the functions in the file.
This model works perfectly on V8: https://stackoverflow.com/a/68053222/11462274
function installFunctions() {
const excludedFunctions = ["onOpen", "installFunctions"];
const menu = SpreadsheetApp.getUi().createMenu('Funções do GAS');
for (let i in this) {
if (typeof this[i] == "function" && !excludedFunctions.includes(i)) {
menu.addItem(i, i);
}
}
menu.addToUi();
}
function onOpen() {
installFunctions();
}
However, in Legacy mode it doesn't work, so I was initially asked to make these changes: https://stackoverflow.com/a/68064124/11462274
function installFunctions() {
var excludedFunctions = ["onOpen", "installFunctions"];
var menu = SpreadsheetApp.getUi().createMenu('Funções do GAS');
for (var i in this) {
if (typeof this[i] == "function" && !excludedFunctions.includes(i)) {
menu.addItem(i, i);
}
}
menu.addToUi();
}
function onOpen() {
installFunctions();
}
But, it returns the error mentioned in the question TypeError: Cannot find includes function in object onOpen,installFunctions., so I saw an indication to change the includes for indexOf, the Menu is created, but only with the OnOpen function appear, which in this case actually shouldn't appear because it should be excluded.
Full Script Test:
function installFunctions() {
var excludedFunctions = ["onOpen", "installFunctions"];
var menu = SpreadsheetApp.getUi().createMenu('Funções do GAS');
for (var i in this) {
if (typeof this[i] == "function" && !excludedFunctions.includes(i)) {
menu.addItem(i, i);
}
}
menu.addToUi();
}
function onOpen() {
installFunctions();
}
function ClimaParaTestes() {
}
function JogosParaClimaParaTestes() {
}
function EnviarClimasParaSquads() {
}
function ApagarHistoricoDoClima() {
}
function deleteTriggerWithName(name) {
}
What do I need to modify in the script to make it work in Legacy mode?

otherFunctionand that's the only one that popped into the menu using Legacy mode.includesdefinitely works and no errors similar to yours. I did encounter an issue before making it work and it's not related to includes (just an error resulting to empty menu). Just added another function and it worked.var excludedFunctions = new Array("onOpen", "installFunctions");instead? It seems the issue in your case is that it reads your excluded functions as object. I wonder if it works usingArray()function. Reference, w3schools.com/js/js_arrays.asp