简体   繁体   中英

How to allow function in protected Google Sheets?

I am using below code to get the last update date in Column B. Now when I protect the column B (because I don't want the other users to make any changes) and share this sheet with other users the update is not happening.

I would appreciate your help.

function onEdit() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheetName = "Sheet1";
  var s = SpreadsheetApp.getActiveSheet();
  if (s.getName() !== sheetName) return;
  var r = s.getActiveCell();
  if( r.getColumn() != 2 ) { //checks the column
    var row = r.getRow();
    var time = new Date();
    time = Utilities.formatDate(time, "GMT+5", "dd/MM/yy, hh:mm:ss");
    SpreadsheetApp.getActiveSheet().getRange('B' + row.toString()).setValue(time);
  };
 };

Instead of using an simple trigger use an installable trigger.

The above is because simple triggers are only able to execute tasks that don't require authorization.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM