Recently, I came across an interesting requirement on the reports in AX 2012. If the total number of pages that gets rendered to the report is more than some X pages, the report should get saved to pdf, if not send it as an email.
Tricky part is how do I get the number of pages [page count] after the report got rendered. I tried to get the number of pages before rendering the report but was unsuccessful by using the adapter class and getNumberOfPages() method.
Finally, I found a solution. On Controller classes there is a method by name “reportViewerRefreshComplete” which can be overridden. This method gets triggered once the data has been rendered on to report viewer.
Override the “reportViewerRefreshComplete” method on any controller class and add the below code. This will help to get the count of printed physical pages on to report.
public void reportViewerRefreshComplete(SRSReportExecutionInfo _executionInfo)
page = this.getReportContract().parmReportExecutionInfo().parmPrintedPhysicalPages();
info(“Total number of pages:” + int2str(page));
Below is the infolog with the counter of pages, after the report data got rendered on to report viewer.