“Service Error: Spreadsheets” Error - Google Scrip

2020-06-07 03:16发布

问题:

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);
}

回答1:

This seems to be a bug!

Searching on the Internet about your issue I came across the following issue on Google Issue Tracker:


Apps Script Set and Get Protection Service Error


It seems a lot of people are having the same problem as you and it all started yesterday (5th February 2020). You can hit the ☆ next to the issue number in the top left on this page as it lets Google know more people are encountering this and so it is more likely to be seen to faster.

I hope this can be useful to you.