Hi good day guys, would like to ask your opinion on how to best avoid this error or Destroy a function when moving to another page in reactive web app.

On my Layout I have block for session timeout with OnReady event.

_idleSecondsTimer = window.setInterval(CheckIdleTime, 1000);

function CheckIdleTime() {
    _idleSecondsCounter++;
    if (_idleSecondsCounter >= IDLE_TIMEOUT) {
            window.clearInterval(_idleSecondsTimer);
            $actions.ReturnTimeout();
    }
}

So the error appears due to it executing on every screen and i think each of them are getting their own instance of the timer onReady.

Invalid call of the 'ReturnTimeout' client action of the 'MainFlow.Screen1' since the latter is not currently active. This is likely due to a platform's client action being used as an event handler or in a setTimeout function. Consider removing this call by using the 'On Destroy' event of the screen/block or moving your logic to a global client action.

Is there a way I can do a proper on destroy event to a javascript from OnReady?

Hi Clintjie,

I think it is happening because everytime you open any page a new instance of setinterval is created. So have you tried clearing existing interval instance first before creating new. To do that before your first statement

_idleSecondsTimer = window.setInterval(CheckIdleTime, 1000);

You should add another statement link this.

if(window.hasOwnProperty('_idleSecondsTimer')) {

window.clearInterval(_idleSecondsTimer);

}

Let me know if this works.