How to auto-refresh custom heatmap widget on dashboard without manual reload?

vkolokythas
Tera Contributor

 

Hi everyone,

I’ve built a custom heatmap for a dashboard using a client script + Script Include. The data is pulled via a GlideAjax call and then rendered into a heatmap table.

Currently, the heatmap only loads when I manually refresh the dashboard.
Here the ui widget that i use to load the ui page to to the widget:

function sections() {
    return {
        'Custom Heatmap': { 'uiPageName' : 'Custom Heatmap'}
    };
}

function render() {
    var uiPageName = renderer.getPreferences().get("uiPageName");
    return renderer.getRenderedPage(uiPageName);
}

function getEditLink() {
    var uiPageName = renderer.getPreference('uiPageName');
    return 'sys_ui_page.do?sysparm_query=' + encodeURIComponent('name=' + uiPageName);
}



Here’s a simplified version of my client script :

 

 
var ga = new GlideAjax('ContractHeatmap'); ga.addParam('sysparm_name', 'getHeatmapData'); ga.getXMLAnswer(function(response) { try { var heatmapData = JSON.parse(response); renderHeatmap(heatmapData);
...... } catch (e) { // handle error } });
 

And the Script Include just aggregates some table data, groups it by two fields, and returns a JSON object.

Question:
What’s the best way to automatically reload or auto-refresh this heatmap data on the dashboard at a set interval (say every 30 seconds or 1 minute) without requiring a manual page refresh?

I want the dashboard to show the latest data continuously, but I’m not sure of the cleanest approach in ServiceNow (interval timers, using $scope.$broadcast, or another pattern).

Thanks in advance!

1 REPLY 1

M Iftikhar
Kilo Sage

Hi @vkolokythas ,

To display the latest data continuously, you have a few options:

  • If you’re building the dashboard in Service Portal, use spUtil.recordWatch to auto-refresh the widget when underlying data changes.

  • Alternatively, consider using a Workspace instead of a dashboard, as Workspaces natively handle auto-refresh.

  • You can also explore the Dashboard Auto Refresh Widget available on the Developer site.

Thanks & Regards,
Muhammad Iftikhar
If my response helped, please mark it as the accepted solution so others can benefit as well.