Hey, I have a form that users can submit and then an admin can approve using a Switch component. When the admin toggles the switch it’s automatically recorded in the sheets, and then I hide it using visibility filter.
I would like to record the timestamp of the action - to have another column in the sheets that will add the current time when the switch field is 'TRUE".
I was trying many techniques I found online, but couldn’t get the NOW() to stay fixed.
Does anyone have any tips on how to add a timestamp on a switch?
function onEdit(e) {
var ss = SpreadsheetApp.getActiveSheet();
var r = ss.getActiveCell();
if (r.getColumn() < 2 && ss.getName()==‘Timestamp update’) {
var celladdress =‘B’+ r.getRowIndex()
ss.getRange(celladdress).setValue(new Date()).setNumberFormat(“MM/dd/yyyy hh:mm”);
}
};
Change ‘Timestamp update’ to your sheet name
Chang B in celladdress = ‘B’ to the column in said sheet you want to have the timestamp
Yeah try it and give me an update, I’m willing to offer more help if needed (it’s 11pm here in Vietnam so might be a little bit delayed, I will check it when I’m up in the morning).
function onEdit(e) {
var ss = SpreadsheetApp.getActiveSheet();
var r = ss.getActiveCell();
if (r.getColumn() < 2 && ss.getName()==‘TIME’) {
var celladdress =‘B’+ r.getRowIndex();
ss.getRange(celladdress).setValue(new Date()).setNumberFormat(“MM/dd/yyyy hh:mm”);
}
};
I tried it still I get the same error.
I have replicated the exact sheet you prepared, the only diff is the sheet name. “TIME”
function onEdit(e) {
var ss = SpreadsheetApp.getActiveSheet();
var r = ss.getActiveCell();
if (r.getColumn() < 2 && ss.getName()==‘TIME’) {
var celladdress =‘B’+ r.getRowIndex();
ss.getRange(celladdress).setValue(new Date()).setNumberFormat(“MM/dd/yyyy hh:mm”);
};
};
You can either add it in the editor (with the right type), it will show up in the Sheets, or you can just add it straight to your sheet and refresh the data.
Mind you not every column will be synced back to Sheet. Maths, relations, lookups, user-specifics etc. won’t be synced back.
What I meant was, Right now the only columns that triggers timestamp is when Row ‘A#’ is edited, which can update any columns’ row. How do I use this script to use specific Columns only say row ‘C#’ to timestamp in ‘D’?