I want to send information from Slack into a new row in a Google Sheet and include a timestamp indicating when that row was added.
Following Slack instructions on how to Send Information into a Google Sheet I have successfully added a row, but do not see how to send a timestamp along with it.
I found a Google Apps script from this Stackoverflow page to add a timestamp when a cell is edited:
function onEdit() {
var s = SpreadsheetApp.getActiveSheet();
if( s.getName() == "Sheet1" ) { //checks that we're on the correct sheet
var r = s.getActiveCell();
if( r.getColumn() == 1 ) { //checks the column
var nextCell = r.offset(0, 1);
if( nextCell.getValue() === '' ) //is empty?
nextCell.setValue(new Date());
}
}
}
The script adds a timestamp when I manually enter data into the Google spreadsheet, but when I add a new row from Slack, no timestamp appears.
This Stackoverflow post is about a similar issue. It explains that there's a difference between pasting and editing, so I think my problem is related. But I still don't understand what exact changes to make in the script above, and I wasn't able to implement the corrected script on that page successfully either.
Can someone help me either
- tweak the script above so it will work when I'm adding a row from Slack; or
- figure out another way to send a timestamp from Slack as part of that row of data?
Thank you!