Auto Refresh Dashboard Based On Elasticube Build Or Refresh Every Dashboard Widget
Auto-refresh dashboard based on Elasticube build: This dashboard script queries the elasticube on the server, and checks to see if a new build has completed. As soon as a build is finished, the dashboard will auto-refresh, and all widgets will be based on the most recent build.
Add this to a dashboard script:
// Specify the required parameters
var reloadType = 'page'; // 'dashboard' (dashboard refresh only) or 'page' (entire page reload)
var checkInterval = 15; // checking interval in seconds
//Variables + Settings to check elasticube build on the server
var cubeName = dashboard.datasource.title;
var encodedCubeName = encodeURIComponent(cubeName);
var revision = null;
var settings = {
"async": true,
"crossDomain": true,
"url": "/api/v1/elasticubes/live/by_title/" + encodedCubeName,
"method": "GET",
"headers": {
"Content-Type": "application/json"
}
}
//The function to look up the revision history of the build. If the revision changes, a build had occurred and the auto-refresh is triggered
function checkElasticubeBuildStatus(){
console.log("Checking cube status...")
$.ajax(settings).done(function (response) {
if(revision === null) {
console.log("Initial dashboard load.");
}
else if(revision != response.lastBuildTime) {
console.log("Cube has recently been updated. Reloading the dashboard...");
if(reloadType === 'page') {
location.reload();
}
else if (reloadType === 'dashboard') {
dashboard.refresh();
}
}
else {
console.log("Cube has not been updated.");
}
revision = response.lastBuildTime;
console.log("Check completed. Next check in " + checkInterval + " seconds.");
setTimeout(checkElasticubeBuildStatus, checkInterval*1000);
});
}
//Run the function to recursively check build status
checkElasticubeBuildStatus();
Auto-refresh dashboard at a set interval:
This script auto-refreshes the dashboard at a set interval. The example below is configured to refresh all widgets every 60 seconds.
Add this to a dashboard script
// Specify the required parameters
var reloadType = 'dashboard'; // 'dashboard' (dashboard refresh only) or 'page' (entire page reload)
var refreshInterval = 10; // refresh interval in seconds
dashboard.on('initialized', function(dashboard, ev){
var refreshDashboard = function(){
if(reloadType === 'page') {
location.reload();
}
else if (reloadType === 'dashboard') {
dashboard.refresh();
}
setTimeout(refreshDashboard, refreshInterval*1000);
}
setTimeout(refreshDashboard, refreshInterval*1000);
})
Updated 11-20-2025
intapiuser
Admin
Joined December 15, 2022