Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Show Total page count in body of report
krahe
I'm developing a BIRT (2.6.1) report that is essentially a shipping document where the last page must include a reference to the total number of pages in the document, followed by space for a signature and another paragraph of verbiage. The Total Page Count AutoText item won't work because I can only use that on a master page, which is every page, not just the last one. My idea is to use a Dynamic Text item to reference a Report Variable that is initialized to 0 and incremented at the start of each new page, which means that once my dynamic text item prints on the last page it should contain the total number of pages in the report. However, while it appears I can create an onPageStart script that ought to update the global variable, I can't seem to get the script to fire, or it's not actually updating the variable. I've tried attaching it to the Master Page as well as the Layout itself, but neither works. I'm currently using a RunAndRender task rather than separate run and render. I've seen conflicting information about using scripts and global/persistent variables with RunAndRender vs. separate tasks. Here is the code I'm using in the script:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>reportContext.setGlobalVariable( "GlobalPageNum", parseInt( reportContext.getGlobalVariable( "GlobalPageNum" ) ) + 1 );</pre>
<br />
Thanks for any help.
Find more posts tagged with
Comments
krahe
I was able to determine that my scripts are firing, but I'm only able to determine the number of pages by forcing page breaks with a Page Break Interval set on the one Table that can break across pages. One funny thing is that the page count shown on the last page of my report is actually one less than the page count computed in the final execution of the onPageBreak script, but I compensated by initializing my page count to 1 instead of 0. Also, it appears that the global variables accessed using reportContext.get/setGlobalVariable() are <strong class='bbc'>not</strong> the same as the "Global" variables defined in the Data Explorer. (Of what use those are I do not know.)<br />
<br />
The one thing I would still like to be able to do is change the Page Break Interval on my Table after the first page break, since subsequent pages have room for more rows than the first, which has a large header section that appears before the table starts.
krahe
I figured out how to show fewer rows on the first page as well. To do that I set the Page Break Interval to the number of rows I want on pages after the first. Then I created an onCreate script on the table detail row, and in there increment a row counter. When the row counter gets to the point where I want to break on the first page and my page counter is 1, I set the page break interval to "always". Otherwise, I set it to "auto". Here is the code for table.detailRow.onCreate:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>rowCount = parseInt( reportContext.getGlobalVariable( "GlobalRowCount" ) ) + 1;
if ( ( rowCount > 6 ) &&
( parseInt( reportContext.getGlobalVariable( "GlobalPageNum" ) ) == 1 ) )
{
this.getStyle().pageBreakAfter = "always";
}
else
{
this.getStyle().pageBreakAfter = "auto";
}
reportContext.setGlobalVariable( "GlobalRowCount", rowCount );</pre>
<br />
(Note that GlobalRowCount is set to 1 in the reportDesign.initialize script.)