0

To be concrete, I think that the method .protect for sheet objects is not working, I have a code that adds a protection to a sheet triggered by a custom menu function, the code was working perfectly until yesterday that throws an exception , my code is something like this

function setProtection(fila){
  if(fila == undefined){
    do{
      //check some conditions
    }while(isNaN(fila) || fila == undefined || fila<4);
  }
  var link = bitacora.getRange(fila, 5).getValue();
  console.log('Este es el link: '+link)  //I put logs just to see where does the code was stopping
  var id = link.split('/')[5]
  var protection = SpreadsheetApp.openById(id).getSheets()[0].protect();
  console.log('Se obtuvo la proteccion');
  var me = Session.getEffectiveUser();
  console.log(me)
  protection.addEditor(me);
  protection.removeEditors(protection.getEditors());
  if (protection.canDomainEdit()) {
    protection.setDomainEdit(false);
  }
  console.log('Terminé de modificar la protección')
  protection.addEditor(//add someone);
}

The thing is that the function stops now at the line:

  var protection = SpreadsheetApp.openById(id).getSheets()[0].protect();

So I tried to see if it had something to do with permissions or anything else, but I am the owner of the file that I am trying to edit, the odd thing is that the protection is indeed set but then there is an exception that is thrown: "Service error: Spradsheets"

So I tried to isolate the problem on a new function just trying to set a protection in another sheet

  var protection = SpreadsheetApp.openById(randomFileId).getSheets()[0].protect();

The problem persists, does anyone knows how to solve this?

Thank you in advance

  • I have the exact same issue - worked fine a few days ago, today it doesn't. – Toby Shepheard Feb 05 '20 at 20:03
  • I also met this issue – kuo chang Feb 06 '20 at 03:40
  • I tried reproducing this error to no avail (It is working as expected for me) – Aerials Feb 06 '20 at 09:42
  • 1
    Does this answer your question? [sheet.getProtections no longer works?](https://stackoverflow.com/questions/60092877/sheet-getprotections-no-longer-works) – Kos Feb 06 '20 at 15:48
  • @Kos well is the same problem (with a different called method) it does not solve it because there is no anwer, but could be the same root cause. I'll give a star to that issue on the google issue tracker – AR_Tecnologia Feb 06 '20 at 21:00

0 Answers0