Assuming you have a dashboard that display data that is affected frequently though the day. You would need to refresh the data shown regularly. However, OutSystems' DataActions and Aggregates do not have an auto refresh functionality.
DataActions and Aggregates can be refreshed in the logic flow from client side. So we want the refresh to be triggered from client side.
1. Create Refresh Action
First step is to create a flow where all the your data fetching logic is applied. Make sure it is the same logic applied when the screen is initialized, to avoid any inconstancies.
2. Define the Auto-refresh Mechanism
To define an auto refreshing behavior, we are going to use JavaScript's "setInterval" function.
setInterval: https://www.w3schools.com/jsref/met_win_setinterval.asp
We need to define the setInterval either in the "OnReady" screen event (when triggering at the start), or the "OnAfterFetch" of the DataAction or the Aggregate (if we want to fetch data once before setting auto refresh).
*Make sure to save the interval Id as we are going to need it to stop the interval later on.
3. Stop Auto-refresh
Since we are using "setInterval", we need to stop it manually using "clearInterval".
clearInterval: https://www.w3schools.com/jsref/met_win_clearinterval.asp
In the "OnDestory" event of the screen/block stop the interval, so that it shall not be triggered when the target client action no longer active.
Finally, you can find a demo on how to use "setInterval" in OutSystems (doc "SetInterval.oml") attached to this post.
Very helpful
Thank you @Mustafa Emad Shaker for sharing these useful tips
Hope it be a useful piece of information.
@Mustafa Emad Shaker
Your implementation needs some modification. You need to clear interval on destroy of your page like below.
Else it will show warning on service center you move to other page.
Thanks @Muhammad Mahmudul Hasan for reviewing the post.
But I had already mentioned that the developer should stop the "setInterval" action. In step #3, "Stop Auto-refresh", you can find in the screenshot that I used "clearInterval" in the OnDestory screen event.
Also, you can find in the 1st step, that I had saved the interval Id after I defined the "setInterval" in the OnReady screen event. And the Id is saved in a local variable visible in all screenshots, "Interval".
Hello, while your approach works for basic scenarios, I'd like to point out that using setInterval for dashboard refreshing is actually an anti-pattern that creates unnecessary server load and doesn't scale well.
The Problem with Polling:
Modern solutions:
Server-Sent Events (SSE) - Link
WebSockets via 3rd party
SignalR via 3rd party
These approaches are event-driven: the server pushes updates only when data actually changes, rather than the client constantly asking "any updates? any updates? any updates?"
Better Architecture:
Greetings,
Claudio
Thanks @Claudio Barra for sharing this information.
I just need to mention that the logic running every X seconds was a typo, the targeted interval was 5 minutes, if the screen was still on (interval cleared when screen is destroyed).
I would like to hint at a correction. In the 3rd screenshot, the "refreshInterval" variable were not used, instead a of the fixed value, 1000 ms.
You can find the right code snapshot here: