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?
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?
Tagged:
8
Categories
- 7.9K Questions
- 926 Ideas
- 220 Discussion Categories
- 178 General
- 9 Community Feedback
- 3 Community Info
- 18 Knowledge Base
Comments
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
Snippet code: Update the waitTime var to amount of time you want. NOTE: the setTimeout function uses milliseconds.
Taking from Seth's example, it would look something like this (also updated to do it once per hour): 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 60*60*1000), which will be once every 3 seconds.
- Chris
Updating the model is the way to go...
I am choosing 'Inline' as the Resource Location and using the following code: Any pointers?
Thanks!
You should be able to do this by calling Hope that helps!
Emily
using my model name it doesnt seem to refresh at all?
Have I missed something?
Look for Moshe's comment in this post about defining '$' to skuid. You need to add the 'var $ = skuid.$;' after the function declaration to skuid. Or you can create a new inline script and Skuid will add the right boilerplate for you. Then just copy your code into the new script.
Thanks,
Bill
The slowness issues were memory related and would build up the longer they had the page up. Which seems to point to a memory leak of some sorts.
Does anyone have any suggestions? Is there a better way to write the snippet to account for this or is a refresh every second unrealistic?
My gut was an every second refresh is too often, but it has worked for over a year with no issues, which makes me wonder if one of the recent updates to the platform has made this version of the snippet not function as well/cause a memory leak.
Anyway, I know this is random, but any suggestions are appreciated.
Thank you!
Adam
(function(skuid){
$(document.body).one("pageload", function(){
var myModel = skuid.model.getModel('NewModelNotes');
var waitTime = 1 * 6 * 1000; // 60 minutes time 60 seconds time 1000 milliseconds
setInterval(function() {
myModel.updateData();
}, waitTime);
});
})(skuid);
This script may be working. I would add a console.log('refresh'); under the "setInterval(function) {" line. Then watch the console to see if the script is running.
The other thing that you may need to do is render the component where you want to see the data update.
Thanks,
Bill
Here's the snippet:
var params = arguments[0],
$ = skuid.$;
pollmodel = params.row.PollModel;
updatemodel = params.row.UpdateModel;
pollinterval = params.row.Polling_Interval;
checkModel = skuid.$M(pollmodel);
updateModel = skuid.$M(updatemodel);
$(function(event){
// THe names of the Models that should be checked every so often for updates
// These should NOT be the Models associated with Charts / Tables, etc.
var RECENT_UPDATES_MODELS = [
pollmodel
];
// Each of our Models should have a Condition named "LastModifiedDate"
var COMMON_CONDITION_NAME = "LastModifiedDate";
var milliseconds = pollinterval * 1000;
var RecentUpdates = $.map(RECENT_UPDATES_MODELS,function(modelId){ return skuid.$M(modelId); });
setInterval(function(){
var now = new Date();
var previous = new Date(now.getTime() - milliseconds);
$.each(RecentUpdates,function(i,model){
var condition = model.getConditionByName(COMMON_CONDITION_NAME,true);
var sfDateTime = skuid.time.getSFDateTime(previous);
model.setCondition(condition,previous);
});
$.when(skuid.model.updateData(RecentUpdates))
.done(function(){
var foundModelWithUpdates = false;
$.each(RecentUpdates,function(i,model){
if (model.getRows().length) {
foundModelWithUpdates = true;
}
});
if (foundModelWithUpdates) {
var modelsToUpdate = [];
if (checkModel && checkModel.getRows().length && updateModel) {
modelsToUpdate.push(updateModel);
}
$.when(skuid.model.updateData(modelsToUpdate))
.done(function(){
//Placeholder for future post update actions
});
}
});
},milliseconds);
});
The example opportunity dashboard uses an inline resource, and we converted it to a snippet that we can invoke more dynamically. We use a lot of page includes in our site and have found that snippets are way more reliable than in-line code when the DOM is swapping around and loading in different sequences. If I were to make one tweak, it would be to pull the filter field (i.e. LastModifiedDate) into the UI Model and use it as a parameter in the javascript. That way all the business logic would be outside the code.