Quantcast
Channel: Hot Weekly Questions - Web Applications Stack Exchange
Viewing all articles
Browse latest Browse all 9788

Google sheets: How to use a script in library?

$
0
0

I'm new to this area, but I'm trying to make the script below work in the library, but it seems not to be working. Since I need to use the scripts in multiple sheets, it is much better if I use the libraries, right? Rather than have a multiple script file. Can someone help me to figure out what seems to be the problem here?

Here's the script that I want to use in the library

const row10 = SpreadsheetApp.getActiveSheet().getRange('B10').getValue();const con_title = "Confirmation";const con_body = "Are you sure you want to lock this sheet?";const suc_title = "Success!";const suc_body = "The sheet is now locked!";const toast_title = "WARNING!!";const toast_body = "Please wait for the SUCCESS dialog box to appear...";var me = Session.getEffectiveUser();function doGet(e) {  this[e.parameter.run](e.parameter.sheetName || null);  return ContentService.createTextOutput('It worked!');}function pro_row10() {  const activeSheet = SpreadsheetApp.getActiveSheet();  const url = ScriptApp.getService().getUrl();  var confirm = Browser.msgBox(con_title,con_body,Browser.Buttons.YES_NO);     if(confirm =='yes'){        SpreadsheetApp.getActiveSpreadsheet().toast(toast_body, toast_title);        UrlFetchApp.fetch(url +"?run=protect&sheetName=" + row10, {headers: {authorization: "Bearer " + ScriptApp.getOAuthToken()}});        Browser.msgBox(suc_title,suc_body,Browser.Buttons.OK);     }}function protect(sheetName){  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName);  var protection = sheet.getProtections(SpreadsheetApp.ProtectionType.SHEET)[0];    if (protection && protection.canEdit() && sheet.protect().setDescription('Sample protected range')) {      protection.remove();    }  Pro_Sheet(sheet);}function Pro_Sheet(sheet) {  var protection = sheet.protect().setDescription('Sample protected sheet');  var me = Session.getEffectiveUser();  protection.addEditor(me);  protection.removeEditors(protection.getEditors());  if (protection.canDomainEdit()) {    protection.setDomainEdit(false);  }}

Here's what I'm using in the main sheet

function pro_row10() { lock.pro_row10();  \\lock is the identifier in the library}

Viewing all articles
Browse latest Browse all 9788

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>