I have this script running for a file that I share with 10 other colleagues.
Problem: Occasionally the script failed to generate a timestamp in Col22 although Col17 is filled in manually. What could be the issue?
function onEdit(e){
const row = e.range.getRow();
const col = e.range.getColumn();
const sheetname = "Intake";
const currentDate = new Date();
const value = e.range.getValue();
const Email = Session.getActiveUser().getEmail();
const lock = LockService.getScriptLock();
var success = lock.tryLock(10000);
if(success) {
if(col===17 && row > 1 && e.source.getActiveSheet().getName() === sheetname && value != "" ){
if(e.source.getActiveSheet().getRange(row,22).getValue() == ""){
e.source.getActiveSheet().getRange(row,22).setValue(currentDate);
}
}
if(col===20 && row > 1 && e.source.getActiveSheet().getName() === sheetname && value === "Pass"){
if(e.source.getActiveSheet().getRange(row,21).getValue() == ""){
e.source.getActiveSheet().getRange(row,21).setValue(currentDate) &&
e.source.getActiveSheet().getRange(row,24).setValue(Email);
}
}
if ((e.source.getActiveSheet().getName() === sheetname) &&
(col === 15 && row > 1 && value !="") ||
(col === 16 && row > 1 && value !="")||
(col === 20 && row > 1 && value === "Pass")) {
let protection = e.range.protect();
protection.addEditor("xxx@yyyy.com");
protection.removeEditors(protection.getEditors());
if (protection.canDomainEdit()) {
protection.setDomainEdit(false);
}
}
}
lock.releaseLock();
}
I read that I need to include EventObject which I did. Other than that I didnt do anything. Thank you!