This script here renames the sheetnames with the value in A1. I manage a school database with over 150 sheets. The script is throwing a maximum time execution timeout error. I have read on the forums here that you can reduce service calls. This here Google app script timeout ~ 5 minutes? looks like a solution but I can't in the life of me wrap my head around what's going on.
I should probably mention that I am a complete noob and your help will be of immense help.
function onEdit() {
var ss = SpreadsheetApp.getActive();
var allsheets = ss.getSheets();
// Array holding the names of the sheets to exclude from the execution
var exclude ="Sheet1","Sheet2","Sheet3","Article","Frontpage","Logos","Sheet4","Sheet5","Sheet6","Sheet10"];
for(var s=10;s<allsheets.length;s++) {
var sheet = allsheets[s];
var oldName = sheet.getName();
var newName = sheet.getRange(1,1).getValue();
if (newName.toString().length>0 && newName !== oldName) {
sheet.setName(newName);
// Stop iteration execution if the condition is meet.
if(exclude.indexOf(sheet.getName())==-1) continue;
}
} // end of loop
} // end of function
Kindly help me reduce the number of service calls the script is making or a faster way to avoid the timeout error.
//Updated Script
//Sample code below generating error missing ) after condition
function testArray() {
var arr = ["Sh1","Sh2","Sh3","Sh4","Sh5","Sh6","Sh7","Sh8","Sh9","Sh10"]; //etc etc
var res = [];
arr.forEach(function (element,index) {
if(index>9) {
var sheet = allsheets[s];
var oldName = sheet.getName();
var newName = sheet.getRange(1,1).getValue();
if (newName.toString().length>0 && newName !== oldName) {
sheet.setName(newName); // Stop iteration execution if the condition is meet.
if(exclude.indexOf(sheet.getName())==-1}) continue; //iterable code goes here;
}
// }
});
}