问题
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