具体来说,我认为用于工作表对象的方法.protect无法正常工作,我有一个代码可以为自定义菜单功能触发的工作表添加保护,该代码运行良好,直到昨天引发异常,我的代码就是这样
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);
}
问题在于该函数现在在以下行停止:
var protection = SpreadsheetApp.openById(id).getSheets()[0].protect();
因此,我尝试查看它是否与权限有关,或其他任何原因,但我是我要编辑的文件的所有者,奇怪的是,确实设置了保护,但是有一个抛出的异常: “服务错误:电子表格”
所以我试图在新功能上隔离问题,只是试图在另一张纸上设置保护
var protection = SpreadsheetApp.openById(randomFileId).getSheets()[0].protect();
问题仍然存在,有人知道如何解决吗?
提前谢谢