1421
Views
8
Comments
Solved
Web block to refresh 
Question

I have created a web block which has a carousel which is fetching data from web api and it is showing trending news(used a preparation for the same).I have to used the web block in a web screen and I want that web block to refresh every 5 sec with latest trending news.

I don't want to refresh the same page every 5 sec but only web block.

How can I achieve that?

Please be elaborate as I am new to outsystems.


2026-03-04 12-24-50
Ruben Bonito
 
MVP
Solution

Create a button with a class name "special" (example) and set the visibility to hidden, then define a javascript on your screen like this:

setInterval(function(){
document.querySelector('.special').click();
},5000);

this will click on the button every 5 seconds.

The button should call a screen action that refreshes your web block.


Hope it's clear for you, let me know if you need more help.

KR

Ruben Bonito

UserImage.jpg
Alexander Hagen-Thorn

Ruben Bonito wrote:

Create a button with a class name "special" (example) and set the visibility to hidden, then define a javascript on your screen like this:

setInterval(function(){
document.querySelector('.special').click();
},5000);

this will click on the button every 5 seconds.

The button should call a screen action that refreshes your web block.


Hope it's clear for you, let me know if you need more help.

KR

Ruben Bonito

You do not need a fake button. You can make your javascript timer call an action on the block, like this: 

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

Then your action can refresh the aggregate.

And also worth to mention that a good place for the timer setup javascript (above) is the block's OnInitialize event handler.

Another important thing: if you create and destroy the block many times, you need to clean the timer. To do so:

1) Make your setup js return the timer ID (the return value of window.setInterval

2) Save the ID in block local variable

3) Define OnDestroy handler on the block and use window.clearInterval(timerId) to remove the timer.


2021-03-05 13-56-11
Ricardo Pereira
 
MVP

Hi Shubham,


You can do what Ruben wrote. If you want something without JS (that you have to wrote) you can see this component: https://www.outsystems.com/forge/component/2134/auto-refresh-utils/


Best regards,

Ricardo

2019-05-22 11-30-09
Marcelo Ferreira

Hi Ricardo,

That component is still javascript. You just don't need to do it yourself. But thanks to bring that option here is a really nice component.

Regards,

Marcelo

2026-03-04 12-24-50
Ruben Bonito
 
MVP

Shubham Agarwal

Could you please mark the answer as a solution if that solves your problem.

Thanks =D

UserImage.jpg
Shubham Agarwal

Thanks to everyone

2020-02-28 09-46-54
Eduardo Jauch

Hi Alexander, 

I think the OP was working with Web Applications.
At the present time, Web Applications do not have client actions. This is a possibility only for Mobile applications.

Cheers.

UserImage.jpg
Alexander Hagen-Thorn

Eduardo Jauch wrote:

Hi Alexander, 

I think the OP was working with Web Applications.
At the present time, Web Applications do not have client actions. This is a possibility only for Mobile applications.

Cheers.

Oh true. That's a shame.


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