Data protection issue with other editors except owner in Google App Scripts having onEdit() trigger

混江龙づ霸主 提交于 2020-08-10 18:58:31

问题


I have a google spreadsheets with 6 editors including me as a owner. When any editor except the owner of the sheets selects certain value in the dropdown menu, the onEdit trigger attached with classAttendance() starts working. That's fine. But the issue is, every time the data is protected on the owner name (has edit access) though the user is different editor. It should be on that specific editor name and should have edit access to it. How to solve it?

function classAttendance(e){ 
  var spreadsheet = SpreadsheetApp.getActive();
  var dashboard = spreadsheet.getSheetByName("Dashboard");
  var sheetName = dashboard.getRange("A4").getValue();    
  
  if (e.range.getA1Notation() === 'C6' && e.range.getValue() === "Start 1-Period") {  
      refreshSheet();
      onePeriod();    
  }
  if (e.range.getA1Notation() === 'C6' && e.range.getValue() === "Start 2-Period") {    
      refreshSheet();
      twoPeriod();
  }    
}

function refreshSheet() {   
  //For protecting dashboard while scripts running
  var spreadsheet = SpreadsheetApp.getActive();  
  var dashboard = spreadsheet.getSheetByName("Dashboard");
   
  var rangem = dashboard.getRange("A1:K71");
  
  var timeZone = Session.getScriptTimeZone();
  var stringDate = Utilities.formatDate(new Date(), timeZone, 'dd/MM/yy HH:mm');
  var me = Session.getEffectiveUser();
  var description = 'Scripts running on ' + stringDate + ' by ' + me;
  
  var protectionm = rangem.protect().setDescription(description);  
  protectionm.addEditor(me);
  protectionm.removeEditors(protectionm.getEditors());
  if (protectionm.canDomainEdit()) {
      protectionm.setDomainEdit(false);
  }  
 
 Utilities.sleep(300000);     
 
}

来源:https://stackoverflow.com/questions/63328100/data-protection-issue-with-other-editors-except-owner-in-google-app-scripts-havi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!