Forced Refresh Every Hour?

Hi there - 

Is it possible to automatically refresh a page at a specific interval? 

I am making a sweet dashboard that we would love to put up on a big screen. I’d like it to refresh itself throughout the day. 

Any ideas?

Hey Kaede…

We do this by using the javascript setInterval to call a function, and then in there tell the model to updateData.  That then causes the model to refresh live (or in our case, we use skuid.model.updateData([model1, model2, …[) since we have multiple related models.  No harsh page refresh - just a clean, client-side data update.  Does that work for you?

- Chris

Thanks, Chris! It sounds like it would work! I just don’t know how to actually do it. 

This seems to work. Inline Javascript, (NOT Inline snippet)

Snippet code:

(function(skuid){ var $ = skuid&#46;$; $(document&#46;body)&#46;one("pageload", function(){ &#47;&#47; var myModel = skuid&#46;model&#46;getModel('MyModelId'); &#47;&#47; var myComponent = skuid&#46;component&#46;getById('MyComponentUniqueId'); var waitTime = 2 * 60 * 1000; &#47;&#47; 2 minutes time 60 seconds time 1000 milliseconds setTimeout(function() { window&#46;location&#46;reload(1); }, waitTime); }); })(skuid);<br />

Update the waitTime var to amount of time you want.  NOTE: the setTimeout function uses milliseconds. 

Much better than mine…  

Seth’s approach is very similar … and has the pro/con of a full page reload.  A bit jarring, but also guarantees a full new page.  My approach would just update the model, and update the page inline.  I also think it might only do it once, as setTimeout I think it a single shot whereas setInterval does it over and over again?

Taking from Seth’s example, it would look something like this (also updated to do it once per hour):

(function(skuid){<br /> $(document&#46;body)&#46;one("pageload", function(){<br /> var myModel = skuid&#46;model&#46;getModel('ADD_YOUR_MODEL_NAME_HERE');<br /> var waitTime = 60 * 60 * 1000; &#47;&#47; 60 minutes time 60 seconds time 1000 milliseconds<br /> setInterval(function() { myModel&#46;updateData();
}, waitTime);<br /> });<br />})(skuid); 

I’ll apologize in advance … I didn’t test this code!  Fingers crossed…  To make this easier to test, change the “waitTime” to something really short like “3000” (instead of 60601000), which will be once every 3 seconds.

- Chris

Thanks, guys! A full refresh is exactly what I’m looking for. This works really nicely! 

My quick test had setTimeout which only runs once, BUT since I was reloading the page, it always restarted the setTimeout.

Updating the model is the way to go…

Totally makes sense - forgot that the page load would (of course) restart the timer.

That’s great stuff. Really simple and effective.

I am attempting to auto-refresh a page. I was able to use Seth’s code above and refresh the full page, but I would really like to only refresh the model like you have suggested Chris. However, when I apply your code, everything on the page disappears.

I am choosing ‘Inline’ as the Resource Location and using the following code:

(function(skuid){<br />&nbsp;&nbsp;&nbsp; $(document&#46;body)&#46;one("pageload", function(){<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; var myModel = skuid&#46;model&#46;getModel('SDSupportQueue');<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; var waitTime = 3000;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; setInterval(function() {<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; myModel&#46;updateData();<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }, waitTime);<br />&nbsp;&nbsp;&nbsp; });<br />})(skuid);

Any pointers?


Try defining “$”

(function(skuid){<br>&nbsp; &nbsp; var $ = skuid.$;<br>&nbsp;&nbsp;&nbsp; $(function(){<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; var myModel = skuid.model.getModel('SDSupportQueue');<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; var waitTime = 3000;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; setInterval(function() {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; myModel.updateData();<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }, waitTime);<br>&nbsp;&nbsp;&nbsp; });<br>})(skuid);

That seems to have done it. Thank you!

Any ideas on how to have this refresh a model that is loaded through a Page Include?

The model in the page include should be the same. The model should still be accessible via the model name (skuid.model.geModel). Side note: If you’re working with page includes, make sure that the model names are unique between the parent page and child page.

Does the inline javascript code need to be saved on the parent page?

How can we include more models in to this script? We have two models on a page (where one is Basic model and aggregate model). How can i refresh both the models automatically?

You should be able to do this by calling

var model1 = skuid.model.getModel('MyModel1'),<br> model2 = skuid.model.getModel('MyModel2'); // In the setInterval function... skuid.model.updateData([model1,model2]);

Hope that helps!

Thank you Emily. It worked

Tried this code (inline)

(function(skuid){<br> $(function(){<br> var myModel = skuid.model.getModel('ADD_YOUR_MODEL_NAME_HERE');<br> var waitTime = 60 * 60 * 1000; // 60 minutes time 60 seconds time 1000 milliseconds<br> setInterval(function() { myModel.updateData();
}, waitTime);<br> });<br>


using my model name it doesnt seem to refresh at all?

Have I missed something?