Skip to main content
Nintex Community Menu Bar
Question

Forced Refresh Every Hour?

  • July 9, 2024
  • 27 replies
  • 102 views

Show first post
This topic has been closed for replies.

27 replies

Forum|alt.badge.img+8

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


Forum|alt.badge.img+8

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.