I use Glide Apps. I need to record the date and time any one of 6 different checkboxs are checked inside of Glide Apps. I have used an onEdit function with success when edits are made in the sheet but it will not record posts that come from within glideapps, only edits I make in cells from inside my sheets.
I want to enter a date and time to the next column to the right of each checkbox when checkbox = TRUE with all updates my users make within Glideapps. I have several instances in different sheets that all have a date and time required when the checkbox cell = TRUE. I understand I cant use onEdit as GS doesnt see the changes passed from Glideapps when the checkbox in the app is TRUE even though the cells in my GS update correctly.
I would also like to enter a date in the 2nd column over from the checkbox = TRUE cell and that date and time will update each time the checkbox is checked however the first checkbox should only change the first time the checkbox = TRUE.
Can I use onChange to achieve the desired result and how would I write the script.
Here are two examples of the code I have used successfuly and there is a much larger script (not inc here) that I used which was more verbose but more specific to the rows that the changes were being made in.
function onEdit(e){ if(e.value == "TRUE") e.source.getActiveSheet().getRange(e.range.rowStart,e.range.columnStart+1).setValue(new Date());}function onEdit(e){ if(e.value == "TRUE") e.source.getActiveSheet().getRange(e.range.rowStart,e.range.columnStart+2).setValue(new Date()); else if(e.value == "") e.source.getActiveSheet().getRange(e.range.rowStart,e.range.columnStart+2).setValue(new Date()); else return;}I am now using the following code successfully
function fillDate() { // calls the fillDate function var sh = SpreadsheetApp.getActiveSheet(); // looks at the spreadsheet the script is running in var range = sh.getRange("A2:X"); // sets the range of cells to look in - I is my date column var values = range.getValues(); // sets the variable values to get values for (var i=0; i<values.length; i++) { //sets value of i to 0 and loops till i is greater than 0 if (!values[i][8] && values[i][7]) { //if value i in column 8 or column 7 are greater than 0 range.getCell(i+1, 9).setValue(Utilities.formatDate(new Date(), '=12:00', 'dd-MM-yyyy hh:mm:ss')); // then get column 9 and enter new Date } // Not sure about my comments above and if they are correct. Also I am not sure why line 8 of the code is getCell i+1 else if (!values[i][11] && values[i][10]) { //if value i in column 11 or column 10 are greater than 0 range.getCell(i+1, 12).setValue(Utilities.formatDate(new Date(), '=12:00', 'dd-MM-yyyy hh:mm:ss')); // then get column 12 and enter new Date } // Not sure about my comments above and if they are correct. Also I am not sure why line 8 of the code is getCell i+1 else if (!values[i][17] && values[i][16]) { //if value i in column 11 or column 10 are greater than 0 range.getCell(i+1, 18).setValue(Utilities.formatDate(new Date(), '=12:00', 'dd-MM-yyyy hh:mm:ss')); // then get column 12 and enter new Date } // Not sure about my comments above and if they are correct. Also I am not sure why line 8 of the code is getCell i+1 else if (!values[i][20] && values[i][19]) { //if value i in column 11 or column 10 are greater than 0 range.getCell(i+1, 21).setValue(Utilities.formatDate(new Date(), '=12:00', 'dd-MM-yyyy hh:mm:ss')); // then get column 12 and enter new Date } // Not sure about my comments above and if they are correct. Also I am not sure why line 8 of the code is getCell i+1 else if (!values[i][23] && values[i][22]) { //if value i in column 11 or column 10 are greater than 0 range.getCell(i+1, 24).setValue(Utilities.formatDate(new Date(), '=12:00', 'dd-MM-yyyy hh:mm:ss')); // then get column 12 and enter new Date } // Not sure about my comments above and if they are correct. Also I am not sure why line 8 of the code is getCell i+1 }}






