I have a script that is set to run each night but it times out. It resets protection on ranges according to dates on the sheet. The script has worked for years but now it times out and does not complete running.
I did not write the script but instead inherited it when the coworker who wrote it left.
It is pretty long and I am guessing it could be condensed but I don't know how.
Any help is appreciated.
The beginning of the script removes all protection:
{ var ss = SpreadsheetApp.getActive();var protections = ss.getProtections(SpreadsheetApp.ProtectionType.RANGE);for (var i = 0; i < protections.length; i++) {var protection = protections[i];if (protection.canEdit()) { protection.remove();}}}And then the rest of the script is about 30 versions of this:
{ var ss = SpreadsheetApp.getActive();var source = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Current");var cellA = source.getRange("A2").getValue();var rangeA = ss.getRange('A:D');if (cellA == "Lock"){ var protectionA = rangeA.protect().setDescription('CATEGORIES'); Logger.log var edsA = protectionA.getEditors(); protectionA.removeEditors(edsA); protectionA.addEditor('wellness@cvtechonline.net'); protectionA.addEditor('admin@cvtechonline.net');}}









