I am having an issue in Google Sheets
TypeError: Cannot read property "source" from undefined. (line 7, file "Code")
When Running the following Code Please Help
function onEdit(event)
{
var timezone = "GMT-5";
var timestamp_format = "MM-dd-yyyy-hh-mm-ss";
var updateColName = "Ticket#";
var timeStampColName = "TimeComplete";
var sheet = event.source.getSheetByName('InAndOut');
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);
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…