I am using Temboo to update a Google sheet with sensor data from an Arduino. I am using a script to add time and date stamps to each data entry however since the data is not being entered manually, I am unable to use the onEdit() trigger. I have also tried creating an onChange() trigger as seen below without any luck (trigger parameters were Run: onChange, Events: From spreadsheet on change). Is there a way to do this with or without an installable trigger?
function onChange(e){
var timezone = "GMT+8";
var date_format = "MM/dd/yyyy";
var time_format = "hh:mm:ss";
var updateColName = "sensor";
var DateColName = "date";
var TimeColName = "time";
// update time and date if the sheet is updated via an api call
if (e.changeType == "OTHER") {
var sheet = event.source.getSheetByName('Sheet1'); //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(DateColName);
var timeCol = headers[0].indexOf(TimeColName);
var updateCol = headers[0].indexOf(updateColName);
updateCol = updateCol + 1;
if (dateCol > -1 && timeCol > -1 && index > 1 && editColumn == updateCol) {
// only timestamp if 'Last Updated' header exists, but not in the header row itself!
var cellDate = sheet.getRange(index, dateCol + 1);
var cellTime = sheet.getRange(index, timeCol + 1);
var date = Utilities.formatDate(new Date(), timezone, date_format);
var time = Utilities.formatDate(new Date(), timezone, time_format);
cellDate.setValue(date);
cellTime.setValue(time);
}
}
};
Thanks in advance!