From the beginning I was not very satisfied with this Getdata-Setdata mechanism, which is proclaimed the standard way of displaying field values from the report body in the report header or footer of a NAV RDLC report layout. So I tried to find a more elegant way to accomplish this problem.
Consider report 205, Sales Order, of NAV 2015. One of the problems in this kind of reports is, that you want to print some fields of the sales header in the report header, which is normally not a dynamic header, but prints the same values on every page, by default. This is not too bad, if you always print only one sales order at a time. But the general case is the print of more than one sales order, may be with number of copies per sales order, too, but that doesn’t increase the complexity of the problem.
So how can we accomplish this scenario in an easy way?
As an example, I designed a sample report, which reveals the basic principles of the procedure. Here are the main steps:
1.) Report dataset:
This is a simplified dataset for printing a sales order, which doesn’t contain any peculiarities.
2.) RDLC layout:
The layout contains the usual outer list for the pagebreak between each sales order (see standard reports).
Furthermore, there is one hidden textbox (yellow) at the beginning of the NewPage tablix, which looks at first glance quite similar to the setdata textbox of the standard report 205. But the main advantage is here, that it contains only one function call to a customer code function. This function call is as usual done in the hidden property of the textbox:
The main difference is here, that all fields are evaluated in the SetFields function and there is no need, to list the fields explicitly as a concatenated string.
Now lets take a look at the Code of the report. In the first part, for every field, which is needed in the report header, a public shared variable is declared. In some cases (customer address), arrays are more easy to handle. These variables are filled with the corresponding values from the Fields collection in the function SetFields:
If another field has to be added to the header, the code has to be extended in a straightforward manner.
In order to get the values of the variables into the header, there is no need to use a kind of Getdata function, the public variables can be addressed directly in the textboxes of the header. For example:
That’s all. If you think, that was too easy, try it out yourself and enjoy how it works…
P.S.: A similar approach has been tried here: http://forum.mibuso.com/discussion/63931