Web block to refresh

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.


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

Solution

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

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

Shubham Agarwal

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

Thanks =D

Thanks to everyone

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.


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.

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.