I have Google Sheets running in OnEdit (). When a cell in a specific row is changed to “completed,” an email will be sent to the job owner. While it displays a browser message.
But I want to avoid sending an email in case of accidental selection and changing it after a few seconds.
The amazing problem is that after running Utilities.sleep (10000) and re-reading the cell value to make sure that it is the same, even if it has been changed, it will read the value again as "completed". Is this something related to sleep function?
if (changedColumn == stageColumnIndex) {
var newValue = sheet.getRange(changedRow, changedColumn).getValue();
if (newValue.toLowerCase() == "completed") {
Logger.log('Sleeping');
Utilities.sleep(10000);
var checkedValue = sheet.getRange(changedRow, changedColumn).getValue();
Logger.log('newValue: ' + newValue);
Logger.log('checkedValue: ' + checkedValue);
var announceChange = (checkedValue == newValue);
if (announceChange) {
var streetIndex = 2;
var street = sheet.getRange(changedRow, streetIndex).getValue();
Browser.msgBox("Job completed at " + street + ".");
}
}
}
source
share