in googlesheets put security in a range with sheetname script after sometime and date

PHOTO EMBED

Tue Dec 13 2022 09:43:59 GMT+0000 (Coordinated Universal Time)

Saved by @ash1i #javascript

function protectOnEdit(event) {
  var ss = SpreadsheetApp.getActive();
  var range = ss.getRange('Statutory Comp Jan-23to Dec-23!D6:E10');
  var timeZone = Session.getScriptTimeZone();
  var stringDate = Utilities.formatDate(new Date(), timeZone, '13/12/22 15:10');
  var description = 'Protected on ' + stringDate;
  var protection = range.protect().setDescription(description);

  // below code taken directly from Google's documentation

  var me = Session.getEffectiveUser();

  protection.addEditor(me);
  protection.removeEditors(protection.getEditors());
  if (protection.canDomainEdit()) {
    protection.setDomainEdit(false);
  }
}
content_copyCOPY