Get pages and visuals
After loading a report, you can make a list of pages or visuals that can be directly used to make changes to those instances. You can also create a list to see what visuals are used on a specific page.
How to get a list of pages
The Page class includes properties and methods to a change report page. For example, you can use the defaultSize
property to define the page size as saved in the report, or the getFilters()
method to get all page level filters in the report. For more information, see Page class.
Use getPages
to retrieve a list of the pages in the report. The order of pages returned is in the same order as in the report.
let pages = await report.getPages();
How to get a list of visuals
The VisualDescriptor class includes properties and methods to change a visual in a specific page. For example, you can use the layout
property to define the visual's position, size, and visibility. For more information, see VisualDescriptor class.
Use the getVisuals
async method on the page
instance.
let pages = await page.getVisuals();
Code examples
Retrieve the page collection
The following code example shows how to retrieve a page collection in report, with an example output showing the page name and display name of each object.
let pages = await report.getPages();
let log = "Report pages:";
pages.forEach(function (page) {
log += "\n" + page.name + " - " + page.displayName;
});
console.log(log);
Report pages:
ReportSectioneb8c865100f8508cc533 - Tiles
ReportSection600dd9293d71ade01765 - Market Share
ReportSectiona271643cba2213c935be - YTD Category
ReportSection1c45b5dc6513ae89b4e3 - Sentiment
ReportSection2ff5a27ac612830bbd93 - Tooltip
ReportSection6da8317ad6cbcae5b3bb - Empty Page
Get a list of visuals
This code example shows how to get a list of visuals for the first page.
let pages = await report.getPages();
// Retrieve the first page.
let firstPage = pages[0];
let visuals = await firstPage.getVisuals();
console.log(visuals);
Get the page collection and the visuals of the first page
This example retrieves the page collection and the visuals (with several properties) for the active page.
let activePage = await report.getActivePage();
let visuals = await activePage.getVisuals();
console.log(
visuals.map(function (visual) {
return {
name: visual.name,
type: visual.type,
title: visual.title,
layout: visual.layout
};
}));
Considerations and limitations
The report must be loaded in order to use the getPages
or getVisuals
functions.