Forced Refresh Every Hour?

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?

Thanks!

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?

Avinash,
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!
Emily

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>

})(skuid);



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

Have I missed something?



Dave,

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.

(function(skuid){<br>
&nbsp; &nbsp; <b>var $ = skuid.$;</b>


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

Appreciate the tip

David, my guess is the $(function(){ part is not working. Try replacing this with $(document.body).one(“pageload”, as here:

(function(skuid){<br> $(document.body).one("pageload", 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>

})(skuid);




Hi All, we have been using this code for over a year now to refresh a case queue every second. In the last month we have been having slowness issues and have narrowed it down to this forced refresh. Removing the forced refresh from the page completely resolved the slowness issues we were having. 

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

Trying to setup as inline Snippet, with model, "NewModelNotes " but not working.  Any ideas?

(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);

Allison,

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 approach we’re using that builds on the approaches above, but the code is parameter driven and reusable. We use a UI only model that generates a row on load and has a field with default values for a pollModel, an updateModel and an interval (in seconds) (see Screenshot). Then there is a Model action when a row is created it runs the snippet below. The argument passed into the snippet is the row created when the model is loaded.

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);
});

FYI, the original source for this script was modifying this solution:  https://community.skuid.com/t/real-time-dashboards, which has the full XML for the page.

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.