743
Views
4
Comments
Javascript to Stop a running action

Hey Guyz,

I am trying to do a flow.

When the page is ready,

I need to trigger an action which will run every 5 seconds

But I need to stop that action after 60 seconds.


This is the flow I have created.

In on Ready action.

I have used the two javascript.

The set timeout will run the TimeExpired action after some seconds (Input Parameter Ex:60s)

The set interval will run the RefressData action every 5 seconds. the action follows


This is the TimeExpired action

I am clearing the interval in this action.


But my problem is, the Refresh Data action is still running.

How to stop that?


Thanks,

Keerthi

2017-06-19 07-56-23
Esa Saarinen

One solution is to store TimerHandle to add Outsystems screen local variable and set it like this:

Then screen OnDestroy (or other needs) clear it like this:

 OnDestroy is important to remember to make this so it wont be forgotten hanging there.

2020-08-05 08-52-58
Ruben Goncalves

Hi Keerthi,


The easiest solution is to create 2 timers, as you did. One running every 5s, and one running 60s.

Like Esa said, store the handle of the 2 timers, when the 60s timer run, clear the interval of the first one, something like

var periodTimer = setInterval($action.RefreshData, 5000);

setTimeout(function(timer){clearInterval(timer)}, $parameters.TimeInSeconds * 1000, periodTimer);


Hope this helps,

RG

2020-02-07 09-04-54
Liesbeth

Hi Esa,

I know this is an old issue but i'm hoping you could tell me of what type "TimerHandle' is?


Thanks!

2017-06-19 07-56-23
Esa Saarinen

Hi Liesbeth!
I am sorry, I just noticed your question.
Id is numeric type as you can find e.g. from here:
https://developer.mozilla.org/en-US/docs/Web/API/setInterval
So in Outsystems you can use Integer

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.