How to count report pages in pre-rendered MorphX report?

axapta, dynamics-ax-2009, report, x++

Solution

Sorry, but `pagesTotal` is a "magic" function that delivers the result after the report has finished, which is too late for you to emit a `newPage`.

You will have to count yourself. Luckily X++ is quite good at it!

Declare your counter in `classDeclaration`:

 Counter pc;

Increment your counter in a page header `execute` section:

 pc++;

In fetch add your `newPage` after super() (or on break of customer number):

boolean fetch()
{
    boolean ret = super();
    if (pc mod 2 == 1)
        element.newPage();
    return ret;
}

Problem

We are trying to force a morphX report to be an even number of pages in length (so our auto-folding machine can handle the workload properly) and have been unsuccessful in using `element.pagesTotal()` to do so. How have others gotten a page count for per-entity reports at the element level? (this is dynamics ax 2009)

Original source