Skip to page contentSkip to chat
ServiceNow support
    • Community
      Ask questions, give advice, and connect with fellow ServiceNow professionals.
      Developer
      Build, test, and deploy applications
      Documentation
      Find detailed information about ServiceNow products, apps, features, and releases.
      Impact
      Accelerate ROI and amplify your expertise.
      Learning
      Build skills with instructor-led and online training.
      Partner
      Grow your business with promotions, news, and marketing tools
      ServiceNow
      Learn about ServiceNow products & solutions.
      Store
      Download certified apps and integrations that complement ServiceNow.
      Support
      Manage your instances, access self-help, and get technical support.
How to find references to a report on Homepages and Non responsive Dashboards using JavaScript - Support and Troubleshooting
  • >
  • Knowledge Base
  • >
  • Support and Troubleshooting (Knowledge Base)
  • >
  • How to find references to a report on Homepages and Non responsive Dashboards using JavaScript
KB0749182

How to find references to a report on Homepages and Non responsive Dashboards using JavaScript


1960 Views Last updated : Apr 7, 2024 public Copy Permalink
KB Summary by Now Assist

Issue

Introduction


Sometimes it may be useful to find usages of a report on Homepages and non responsive Dashboards. For example, you may want to remove or redesign a report, but want to measure the impact. The script in this article will search for Homepages and Dashboards that have this report.
If an instance is using a responsive dashboard, the following script might not give accurate results because responsive dashboards use sys_grid_canvas and sys_grid_canvas_pane tables to store contents on the dashboard. 

Usage


The function in the script takes one argument. This should be a string containing the sys ID of the report (sys_report record) you are looking for. This script should be run via the Scripts - Background module.

The Script

Version for homepages and non-responsive dashboards:

findReportReferences('c8b0bce8db25b3003869ff041d961975'); //sys_id for the report
function findReportReferences(report) {
    var pp = new GlideRecord('sys_portal_preferences');
    pp.addQuery('value', report);
    pp.query();
    while (pp.next()) {
        var page = new GlideRecord('sys_portal_page');
        page.get(pp.portal_section.page);
        var tabs = new GlideRecord('pa_tabs');
        tabs.addQuery('page', page.sys_id);
        tabs.query();

        // No PA tabs, it's just a homepage
        if (tabs.getRowCount() < 1) {
            gs.info("Homepage: " + page.title);
            continue;
        }

        // PA tabs exist, it's on a dashboard
        while (tabs.next()) {
            var m2m = new GlideRecord('pa_m2m_dashboard_tabs');
            m2m.addQuery('tab', tabs.sys_id);
            m2m.query();
            while (m2m.next()) {
                gs.info("Dashboard: " + m2m.dashboard.name);
            }
        }
    }
}

Version for responsive dashboards:

var reports = ['01266b8bdb0cf7c46538f7adae9619d0']; // list of report sysIDs
var dashboards = [];
reports.forEach(function(report) {
dashboards = dashboards.concat(getDashboardsForAReport(report))
dashboards = dashboards.filter(function (elem, index, me) { // remove any duplicates exists
return index === me.indexOf(elem);
});
})
gs.log(JSON.stringify(dashboards.join()));
// +++++++++++++++ helper functions +++++++++++++++
function getDashboardsForAReport(sysId) {
var paSysReport = new GlideRecordSecure('sys_report');
var paGaugeReport = new GlideRecordSecure('sys_gauge');
var tabs = [];
if (sysId && paSysReport.get(sysId))
tabs = _getTabsFromWidget(sysId);
if (paGaugeReport.get('report', sysId))
tabs = tabs.concat(_getTabsFromWidget(paGaugeReport.getValue('sys_id')));
tabs = tabs.filter(function (elem, index, me) { // remove any duplicates exists
return index === me.indexOf(elem);
});
var dashboards = [];
tabs.forEach(function (tab) {
dashboards = dashboards.concat(_getDashboardFromTab(tab.tabUniqueId))
});
dashboards = dashboards.filter(function (elem, index, me) { // remove any duplicates exists
return index === me.indexOf(elem);
});
return dashboards;
}
function _getTabsFromWidget(sysId) {
// fetch tabs
var paTabs = null;
var tabs = [];
var gridCanvasPaneList = [];
var record = null;
var i = 0;
var sysGridCanvasPane = null;
var pref = new GlideRecord('sys_portal_preferences');
pref.addQuery('value', sysId);
pref.query();
var portalSections = [];
while (pref.next())
portalSections.push(pref.getValue("portal_section"));
for (i = 0; i < portalSections.length; i++) {
sysGridCanvasPane = new GlideRecord('sys_grid_canvas_pane');
sysGridCanvasPane.addQuery('portal_widget', portalSections[i]);
sysGridCanvasPane.query();
while (sysGridCanvasPane.next())
gridCanvasPaneList.push(sysGridCanvasPane.getValue('grid_canvas'));
}
for (i = 0; i < gridCanvasPaneList.length; i++) {
paTabs = new GlideRecordSecure('pa_tabs');
paTabs.addQuery('canvas_page', gridCanvasPaneList[i]);
paTabs.query();
while (paTabs.next()) {
record = {
id: paTabs.getValue('sys_id'),
tabUniqueId: paTabs.getValue('sys_id'),
name: paTabs.getDisplayValue('name'),
};
tabs.push(record);
}
}
return tabs;
}
function _getDashboardFromTab(tabID) {
var dashboards = [];
var dashBoardTab = new GlideRecordSecure('pa_m2m_dashboard_tabs');
var padDashboard = new GlideRecordSecure('pa_dashboards');
var record = null;
dashBoardTab.addQuery('tab', '=', tabID);
dashBoardTab.query();
while (dashBoardTab.next()) {
dashboards.push(dashBoardTab.getDisplayValue('dashboard.sys_id'));
}
return dashboards;
}

The world works with ServiceNow.

Sign in for more! There's more content available only to authenticated users Sign in for more!
Did this KB article help you?
Did this KB article help you?

How would you rate your Now Support digital experience?

*

Very unsatisfied

Unsatisfied

Neutral

Satisfied

Very satisfied

Very unsatisfied

Unsatisfied

Neutral

Satisfied

Very satisfied

What can we improve? Please select all that apply.

What are we doing well? Please select all that apply.

Tell us more

*

Do you expect a response from this feedback?

  • Terms and conditions
  • Privacy statement
  • GDPR
  • Cookie policy
  • © 2025 ServiceNow. All rights reserved.