Imagine you have to create a report, for example a Document, and there’s certain information, like for example Sales Conditions, that only need to be printed on the footer of the last page. How do you do that in RDLC?
A good thing is always to investigate if there’s a property that you can use. In this case the properties of a header and footer that could help us are: PrintOnFirstPage and PrintOnLastPage. But actually, these two properties allow us to NOT print something on the First and/or Last page, and what we want is the other way around. So, bad luck, these properties will not help us.
Then let’s have a look at the Globals collection. Here we have two interesting Globals:
So, let’s try to use them.
When you use these in a textbox in the body of a report you will get an error:
So adding a textbox to the body of the report and determining via an expression if we are on the last page and then showing/hiding it is not an option. Why would we do this you might think. If you place something at the bottom of the Body it is automatically shown only on the last page, no? Well, in Dynamics NAV Document reports, the Body contains a List, putting it in the List would make it appear on every page and putting it below the List is not an option, because it needs to be shown on the last page, for everydocument.
No problem, let’s put it where it’s allowed, for example the Footer.
To be able to show a field in the dataset on a Footer (or Header) we will need to declare a Variable, a Set function and a Get function:
Shared LastPageInfo as Object Public Function GetLastPageInfo() as Object Return Cstr(LastPageInfo) End Function
Public Function SetLastPageInfo(NewData as Object) If NewData > "" Then LastPageInfo = NewData End If End Function
Now we will create a Layout:
The textbox in the Footer is inside a Rectangle and in the Hidden property of the Rectangle we can set the following expression:
And voila the result:
By the way, on some blogs you might see a solution to be able to show the PageNumber and TotalPages on the Body of the report using an expression like the following:
Function PageNumber() As String Return Me.Report.Globals!PageNumber End Function
But unfortunately it does not work and always shows 1 as the PageNumber (same for TotalPages). Actually there’s a mention on it on Microsoft Connect here. Were basically the answer from Microsoft is: “We will consider adding this as a new feature in a supported, declarative way via RDL ReportObjectModel enhancements in a future release, and in the meantime also monitor customer vote counts.”
I have also tested it on Microsoft Dynamics NAV 2013, with the same result. Maybe when we switch over to RDLC2010 it might become possible 🙂