I'd like to implement a script to implement range protections on the different tabs of the spreadsheet when someone create a new spreadsheet by copying my template.
The issue I encounter is when the script run through the protection implementation.
My code seems to be fine as per the debug tool does not find anything wrong, yet, my script implements only the first protected range.
Here the sample:
function rangeProtect() {
var s = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
if(s.getName()=='Overview') {
var range = s.getRange('A1:K20');
var protection = range.protect().setDescription('Overview');
var me = Session.getEffectiveUser();
var eds = protection.getEditors();
protection.addEditor(me);
protection.removeEditors(eds);
if (protection.canDomainEdit()) {
protection.setDomainEdit(false);
}
}
else if(s.getName()=='Picklist (Buying Ops)') {
var range = s.getRange('A1:H254');
var protection = range.protect().setDescription('Picklist');
var range2 = s.getRange('C5:H254')
var protection2 = range2.protect().setDescription('Buying Ops');
var me = Session.getEffectiveUser();
var eds = protection.getEditors();
var add = raw[11];
protection.addEditor(me);
protection.removeEditors(eds);
protection2.addEditor(add);
if (protection.canDomainEdit()) {
protection.setDomainEdit(false);
}
}
...
Could someone help me on that as I don't see what is wrong here.
Thanks