How to diplay Page Number in the BIRT 3.7.1 report as per the Group By implemented in the report.

Paramartha
edited February 11, 2022 in Analytics #1
<p>Hi,</p>
<p> </p>
<p>I have a query on BIRT report. I am attaching the output of a report in pdf format. The requirement is to restart the page number for each group. There is group by based on Work Order number. Currently the page number are appearing sequentially. for example if total page is 7 then the page number is appearing as 1 of 7 ,2 of 7,3 of 7....7 of 7 . But now the requirement is if there are two Work Order are displaying in the report and for the first work order there 4 pages and for the second work order there will be 3 pages then the page number needs to be appeared is this way: For 1st Work Order 1 of 4, 2 of 4.....4 of 4 and for the 2nd Work Order the page number will be 1 of 3, 2 of 3 and 3 of 3. The BIRT version is 3.7.1.</p>
<p> </p>
<p>Please help me on this. i am waiting for your response with a solution.</p>

Comments

  • <p>This can be accomplished using some JavaScripting.</p>
    <p>There are two parts to this solution, one calculates the pages, the other displays the page numbers.</p>
    <p>Below is the code used for this solution as well as an attached example for reference.</p>
    <p> </p>
    <p>In the Group Footer Row's onCreate method drop in the following code:</p>
    <pre class="_prettyXprint _lang-js">
    //
    //
    // This code group calculates the total number of pages in a Table Group and sets vars based on page number each page in that group
    //
    // To use: Place this entire code block into a Table's Group FooterRow.
    // Call the following global values to retreve their values.
    // For Current Page In Group: reportContext.getPersistentGlobalVariable("PageCounter" + pageNumber.toString());
    // For Total Pages In Group : reportContext.getPersistentGlobalVariable("GroupCounter" + pageNumber.toString());
    //
    // Example:
    // Place the following example into a Dynamic Text element's onRender Method in the Master Page to display "Page n of m" where m is the total pages per group.
    //
    // CurrentPage = reportContext.getPersistentGlobalVariable("PageCounter" + pageNumber.toString()); //Set CurrentPage var from global var "PageCounter"
    // GroupTotal = reportContext.getPersistentGlobalVariable("GroupCounter" + pageNumber.toString()); //Set GroupTotal var from global var "GroupCounter"
    // this.text = "Page " + CurrentPage + " of " + GroupTotal; //Set output text to: Page # of #
    //
    //
    lastGroupPageNum = parseInt(reportContext.getPersistentGlobalVariable("PageHolder")); //Set lastGroupPageNum var from global var "PageHolder"
    if (!lastGroupPageNum) {lastGroupPageNum = 0;} //If this is first run then set lastGroupPageNum to 0
    pagesInGroup = pageNumber - lastGroupPageNum; //Subtract lastGroupPageNum from Current page to get pagesInGroup
    pageDiffCount = pagesInGroup; //Copy pagesInGroup to pageDiffCount
    while (pageDiffCount-- > 0) { //Loop through all pages in a group
    inBetweenPages = lastGroupPageNum + pageDiffCount + 1; //Calculate the inBetweenPages page numbers of the pages between groups
    reportContext.setPersistentGlobalVariable("GroupCounter" + inBetweenPages.toString(),pagesInGroup.toString()); //Set the GroupCounter for each page
    reportContext.setPersistentGlobalVariable("PageCounter" + inBetweenPages.toString(),(pageDiffCount+1).toString()); //Set the PageCounter for each page
    } //End pageDiffCount loop
    reportContext.setPersistentGlobalVariable("PageHolder",pageNumber.toString()); //Set global var "PageHolder" as reference for last group page
    //

    </pre>
    <p>Then on the MasterPage add a Dynamic Text element, then in the Dynamic Text elements onRender method drop in this code to display the page numbers:</p>
    <pre class="_prettyXprint _lang-js">
    //
    //
    // This code group displays "Page n of m" on each page where m is the total number of pages in a Table group.
    //
    // This code requires the logic code found in a Table's Group FooterRow onCreate method to work
    //
    CurrentPage = reportContext.getPersistentGlobalVariable("PageCounter" + pageNumber.toString()); //Set CurrentPage var from global var "PageCounter"
    GroupTotal = reportContext.getPersistentGlobalVariable("GroupCounter" + pageNumber.toString()); //Set GroupTotal var from global var "GroupCounter"
    this.text = "Page " + CurrentPage + " of " + GroupTotal; //Set output text to: Page # of #
    //
    </pre>
    Warning No formatter is installed for the format ipb
  • <p>Hello Matthew,<br>
     <br>
    Thanks for your response and sharing the javascript code.i have implemented your javascript code in the design file as you requested but unfortunately it is not working. I am attaching the design file of the report .If you can look into it and the issue will be resolved it will be very helpful for me.<br>
     <br>
    Thanks is advance.</p>
  • <p>Looking over the design, I realized this is for a Maximo environment.</p>
    <p>There were 2 things I changed in your design.</p>
    <p>1:  I added a 'Group Footer' row and moved the code from the 'Table Footer' row into the 'Group Footer' row.</p>
    <p>2:  Because this report requires a Maximo library to access the MasterPage, I instead added the page number code to the 'Group Header' row in <strong><span style="color:#ff0000;">red</span></strong> so that its easy to spot.  However if you already added the page number code to the Masterpage, then both should show the correct page number results.</p>
    <p> </p>
    <p>Let me know if this works for you in Maximo, or if my previous example works when deployed to Maximo as I know that some report behavior changes when run in a Maximo environment.</p>
    Warning No formatter is installed for the format ipb
  • <p>Hi Matthew,</p>
    <p> </p>
    <p>I have deployed your report design file in the Maximo.The page number is resetting for each group.But there is one problem if there are multiple pages for one group then the page number is not increasing.It is showing alwasy 1of 1.I am attcahnig the pdf output the report design file. </p>
  • <p>If I am not mistaken, this will not work in Maximo as this method requires the run and render tasks to be separate (which is best practice). IBM engineers decided to use the runandrendertask (does both at the same time). I have pointed this out to IBM many times, but they do not listen. Basically in order to renumber pages you need to know ahead of time how many pages are in each group in order to do this we count during the generation and then change it in render time.</p>
    <p> </p>
    <p>The only workaround I can think of is have a separate query that calculates how many pages each group has. This is not trivial as this does not always depend on number of rows alone.</p>
  • <p>This could be due to the way the embedded tables have an effect on the design.</p>
    <p>I moved the 'onCreate' code to the second 'Group Footer' row to see if the behavior changes.</p>
    <p> </p>
    <p>Please let me know if this changes the effect.</p>
    <p>Also, are you able to run this design in the designer?</p>
    <p>Does the behavior change between the designer view and when deployed to Maximo?</p>
    Warning No formatter is installed for the format ipb
  • <p>Hello Mathew,</p>
    <p> </p>
    <p>I have deployed the latest design file which you sent but the result is same as previous. The page number is resetting for each group but the page number is not incrementing for a group if there are multiple pages for a group.</p>
    <p> </p>
    <p>I am bale to run the design file in the BIRT designer but the page number is appearing as blank.The difference between BIRT designer and the Maximo is that while running in BIRT designer the page number is appearing as blank but in Maximo it is showing the value of page number but always it is appearing as 1 of 1.  </p>
    <p> </p>
    <p>Actually it si almost reached only one hurdle is there to increase the page number when there are multiple pages in a group.</p>
  • hi Mathew/paramartha, can you please send the report design file which is working in maximo

  • I am also looking for the same kind of solution, kindly provide the report design file which works for Maximo

  • @Priya_India said:
    I am also looking for the same kind of solution, kindly provide the report design file which works for Maximo

    So am I...is there any solution found please?
    I can't see any report design fetched here :(

    Thanks :)