Potrzebuję w arkuszach google napisać 2 funkcje, które będę mógł uruchamiać jako właściel arkusza.
Nie jestem pewien czy moje myślenie jest prawidłowe. Nie miałem wcześniej do czynienia z Javascript.
Bardzo proszę o wskazówki.
function doGet(e){
var id = e.parameter.id;
//zablokuj arkusz
if(id == 1){
var spreadsheet = SpreadsheetApp.getActive();
spreadsheet.getRange('D10').activate();
var protection = spreadsheet.getActiveSheet().protect();
protection.addEditors(['[email protected]']);
spreadsheet.getRange('A1').activate();
protection.removeEditors(['[email protected]', '[email protected]']);
} else if (id == 2) {
//odblokuj arkusz
var spreadsheet = SpreadsheetApp.getActive();
spreadsheet.getRange('E19').activate();
var allProtections = spreadsheet.getActiveSheet().getProtections(SpreadsheetApp.ProtectionType.SHEET);
var protection = allProtections[0];
protection.remove();
}
return ContentService.createTextOutput();
};
function zablokuj() {
UrlFetchApp.fetch('https://script.google.com/macros/s/###################################################/exec/id=1', {headers: {authorization: "Bearer " + ScriptApp.getOAuthToken()}});
}
function odblokuj() {
UrlFetchApp.fetch('https://script.google.com/macros/s/###################################################/exec/id=2', {headers: {authorization: "Bearer " + ScriptApp.getOAuthToken()}});
}
Kiedy uruchamiam, jako inny użytkownik funkcję (przypisaną do rysunku) zablokuj, to blokuje mi arkusz. Kiedy odblokuj to niestety nie działa.
Czy może mnie ktoś nakierować ?
Czy parametr id przekazuję prawidłowo do funkcji doGet ?
Oczywiście po każdej zmianie robię nowe wdrożenie.