66
Views
10
Comments
Refresh a page every 5 seconds

Hi all

I need to refresh a page on my application, let say, every 5 seconds. I am looking at timers but it doesn't seem to be an option to do that.

I found this old post (2016 and for OutSystems 10) https://www.outsystems.com/forums/discussion/20770/mobile-screen-refresh-on-timer/

but I don't think it applies anymore.

Any suggestion appreciated.

Thanks!

Hi,

You can use this forge component. It has an action called RefreshScreen that is a web block, that you just need to drag to your screen and choose the refresh interval.

Let me know if this helps,

Pedro

I did a search in the OutSystems forums and came up with some solutions:

https://www.outsystems.com/forums/discussion/50537/auto-refresh-web-screen-question/

https://www.outsystems.com/forums/discussion/60783/how-to-refresh-screen-of-reactive-app/

etc, etc


 I'm sure you find some solution overthere

We do this a lot and use the following approach. This way the data is only refreshed 5 seconds after the last fetch of data was complete so if there are any slow queries you don't need to worry about lots of flashing/updating of data on the screen.

Let me know if this helps or any questions

  1. Create a fetch data action screen action that fetches/refreshes all the data sources you need
  2. Create a new screen action to simple refresh that get data action
  3. Create a new action for the "on after fetch" event of the data action in step 1 and include the following JavaScript in it

    setInterval(function(){$actions.$actions.RefreshData()}, 5000);

Hi Adam,

I wanted to give a go to your solution, but something is not right. I attach the oml file of a sample application. Can you please tell me what I have done wrong?

Thanks for your help.

Timer_Test2.oml

Hi @Adam Elleston ,

i see 2 problems with this approach :

  • one single big data action retrieving all data, not making use of the option to asynchronously retrieve parts of your data
  • exponential growth of setIntervals (maybe you mean SetTimeout instead ?)

Dorine

Hey,

First a script in the script section of interface tab. Use the below JS.

Then use script1 in Screen that you want to refresh.


Hope this might help you

Thanks & Regards,

Sudip Pal

You can also use the Timing Events forge component. This component contains 2 blocks (Interval and Timeout) that will trigger on your conditions. The biggest advantages of this component is that both widgets can be turned on and off via an Boolean so you can configure when the timer starts running or when it stops running. 

But although this refresh sounds nice please also consider the performance implications. If you have enough screens open that refresh itself you can DDOS your own environment pretty quickly by overloading your SQL database. Make sure that you protect yourself against this by;

  • Implementing caching
  • Stopping the refresh after some point in time or when the expected data is received.
  • Implementing a different solution based on Server Side Events (for example). 

Hope this helps,

Vincent

When using setTimeout or setInterval via javascript, don't forget to clear them using clearTimeout or clearInterval in the OnDestroy event.

https://success.outsystems.com/documentation/11/developing_an_application/implement_application_logic/screen_and_block_lifecycle_events/#on-destroy


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