Now I see what you are talking about @Jeff_Hager
but here i just want to record the date at which a user selected a date through a date picker (not on a add or edit or form mode
)
@ThinhDinh i feel like you are one of the experts here in Google Script and I am struggling with my script.
I check column 9 and 13 of a specific Sheet, and if something changes in these columns i write the date stamp on the next column to the right.
It always seems to work just fine, both in through the app and though the Google sheet directly, but each day I end up with 5 to 10 script errors. And I really don’t know why. It works, and sometimes randomly it doesn’t…
the error says : Exception: Référence de cellule hors plage
at onChange(Code:13:28) which i think is “Cell out of Range” in English.
Here is my script :
//CORE VARIABLES
// The column you want to check if something is entered.
var COLUMNTOCHECK1 = 9;
var COLUMNTOCHECK2 = 13;
// Where you want the date time stamp offset from the input location. [row, column]
var DATETIMELOCATION = [0,1];
// Sheet you are working on
var SHEETNAME = ‘
BLs’
function onChange(e) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var selectedCell = ss.getActiveCell();
//checks that we’re on the correct sheet.
if( sheet.getSheetName() == SHEETNAME ) {
//checks the column to ensure it is on the one we want to cause the date to appear.
if( selectedCell.getColumn() == COLUMNTOCHECK1) {
var dateTimeCell = selectedCell.offset(DATETIMELOCATION[0],DATETIMELOCATION[1]);
dateTimeCell.setValue(new Date());
}
if( selectedCell.getColumn() == COLUMNTOCHECK2) {
var dateTimeCell = selectedCell.offset(DATETIMELOCATION[0],DATETIMELOCATION[1]);
dateTimeCell.setValue(new Date());
}
}
}
is there something wrong here ?
or is it just normal that sometimes google script can produce errors ? (the error rate is still below 1% but still very annoying).
Thanks a lot for your help !!