I need help with my Google Sheet script. It is working fine when showing the timestamp of "Last Updated" at col B every time a new Call Status was set at col A; but when I delete the status at col A, the timestamp remains at col B. It should also be cleared when no data is selected at col A.
My Script
var timezone = "UTC+00:00";
var timestamp_format = "hh:mm:ss dd/MM/yyyy"; // Timestamp Format.
var updateColName = "Call Status";
var timeStampColName = "Last Updated";
var sheet = event.source.getSheetByName('StatusDate'); //Name of the sheet where you want to run this script.
var actRng = event.source.getActiveRange();
var editColumn = actRng.getColumn();
var index = actRng.getRowIndex();
var headers = sheet.getRange(1, 1, 1, sheet.getLastColumn()).getValues();
var dateCol = headers[0].indexOf(timeStampColName);
var updateCol = headers[0].indexOf(updateColName); updateCol = updateCol+1;
if (dateCol > -1 && index > 1 && editColumn == updateCol) { // only timestamp if 'Last Updated' header exists, but not in the header row itself!
var cell = sheet.getRange(index, dateCol + 1);
var date = Utilities.formatDate(new Date(), timezone, timestamp_format);
cell.setValue(date);
}