I've got a sub function in a project that I use to copy protections as a sheet is duplicated. This has worked for months without issue. I'm suddenly getting an error "Service Error: Spreadsheets" when I run it. I know it worked without issue on Sunday and there has been no changes to the code. With a series of Logger statements I know the error occurs on the line
var p = sheet.getProtections(SpreadsheetApp.ProtectionType.SHEET)[0];
I've done some testing and it appears that most of the protection class commands are triggering the error. I've done a google search and can only find one other relevant post from 15 hours ago with someone running into a similar but slightly problem. It appears to me this is an issue on the google side of things. Can anyone confirm or give any insight as to how to proceed? Are they likely working on something and it'll be fixed soon?
function DuplicateProtections(Week) {
//Duplicates the selected Template keeping all the protections
var sheet = ss.getSheetByName(Week);
var sheet2 = sheet.copyTo(ss).setName('Temp');
var p = sheet.getProtections(SpreadsheetApp.ProtectionType.SHEET)[0];
var p2 = sheet2.protect();
p2.setDescription(p.getDescription());
p2.setWarningOnly(p.isWarningOnly());
if (!p.isWarningOnly()) {
p2.removeEditors(p2.getEditors());
p2.addEditors(p.getEditors());
}
var ranges = p.getUnprotectedRanges();
var newRanges = [];
for (var i = 0; i < ranges.length; i++) {
newRanges.push(sheet2.getRange(ranges[i].getA1Notation()));
}
p2.setUnprotectedRanges(newRanges);
}