I have an onEdit function running fine into googlesheets, it is basically a countdown timer and displays the countdown into a cell. However after around 30 seconds of running, the display no longer updates and just freezes at whatever time it was at, while the countdown still runs down in the background. To have the display "wake up", I have to manually update any cell in the spreadsheet.
I have tried having a RANDBETWEEN formula to recalculate every second the timer ticks down, however this formula update does not "wake up" the countdown display. From my limited understanding only a manual user update will. Is there a way to have the code automatically update itself such that I do not require a manual user update? If so how.
My countdown timer code:
function onEdit(){
const d = new Date();
currTime = d.getTime();
var ss = SpreadsheetApp.getActive();
var sh = ss.getSheetByName('Sheet3');
if (sh.getRange('A1').getValue() == ""){
sh.getRange('A1').setValue(currTime)
}
else {
sh.getRange('A4').setValue(Math.round((sh.getRange("A1").getValue() - currTime)/-1000))
}
SpreadsheetApp.flush();
//if (e.range.getA1Notation() == "G11"){
var ss = SpreadsheetApp.getActive();
var sh = ss.getSheetByName('Sheet3');
var m = sh.getRange('F2').getValue();
var s = sh.getRange('G2').getValue();
const countdown = (m*60 + s) - sh.getRange('A4').getValue()
const cdm = Math.floor(countdown /60);
const cds = countdown % 60;
sh.getRange('D4').setValue(cdm + ":" + cds);
SpreadsheetApp.flush();
if (sh.getRange('F7').getValue() == "r"){
sh.getRange('A1').setValue("")
sh.getRange('F7').setValue("")
SpreadsheetApp.flush();
onEdit();
}
else if (countdown <= 0){
}
else if (sh.getRange('F7').getValue() != "s"){
SpreadsheetApp.flush();
onEdit()
}
//}
}