function - How to implement rangeProtect() over multiple tabs - google spreadsheet -


i'd implement script implement range protections on different tabs of spreadsheet when create new spreadsheet copying template.

the issue encounter when script run through protection implementation.

my code seems fine per debug tool not find wrong, yet, script implements first protected range.

here 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 me on don't see wrong here.

thanks

answering question,

the main script discribs way find sheet , range(s) protect / unprotect, different users using remove/addeditors(mail) function

//main script - protect - can edit function protect_unprotect( myrange,  mysheet,  mydescription, startrow, colnumber, numrows, columncount) {    var ss = spreadsheetapp.getactivespreadsheet().getsheetbyname(mysheet);   var range1 = ss.getrange(myrange);   var protection1 = range1.protect().setdescription(mydescription);   var me = session.geteffectiveuser();   var eds1 = protection1.geteditors();   protection1.addeditor(me);   protection1.removeeditors(eds1);   //incase dont want run part of code, send startrow parameter -1 value   // , rest of parameteres 0   //startrow = first raw fetch datas   //colnumber = column number fetch datas - column = 1   //numrows = number of rows fetch datas   //columncount = number of columns fetch datas   if(startrow > 0) {     var datarange = ss.getrange(startrow, colnumber, numrows, columncount)     var data = datarange.getvalues();     (i in data) {       var row = data[i];       var emailaddress = row[0];       protection1.addeditor(emailaddress);     }   }   if (protection1.candomainedit()) {     protection1.setdomainedit(false);     } } 

the second script recalling main script , indicate apply it.

function rangeprotect() { //script recall main script        protect_unprotect("a1:h", 'overview', '0-overview', -1, 0, 0, 0);       protect_unprotect("a1:b", 'picklist (buying ops)', '1- picklist 1', -1, 0, 0, 0);       protect_unprotect("c1:h2", 'picklist (buying ops)', '1- picklist 2', 5, 11, 2, 1);       protect_unprotect("c3:h4", 'picklist (buying ops)', '1- picklist 3', -1, 0, 0, 0);       protect_unprotect("i1:k", 'picklist (buying ops)', '1- picklist 4', -1, 0, 0, 0);       protect_unprotect("c5:h", 'picklist (buying ops)', '1- buying ops', 5, 11, 2, 1);       protect_unprotect("a1:o", 'dashboard (view only)', '2- dashboard', -1, 0, 0, 0);       ...         } 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -