Notifications

518 views

Description

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

Article Information

Last Updated:2020-03-12 12:16:13
Published:2020-03-12