Dynamic Font Sizes in NAV 2013 Reports

It’s been a while since I’ve posted anything enthusing about NAV reports, so we’ll return to the subject with undiminished vigour. I had an issue with a report today which would have required a clumsy solution with the old, classic NAV reports. In these enlightened days of RDL layouts for RoleTailored Client reports, we can bring a little more finesse to the party.

This example is taken from NAV 2013 and Visual Studio 2010 – but the principle holds good for NAV 2009 as well.

A common problem with reports is fitting all the fields that you need across the width of the page that you are printing to. Especially when one of those fields contains text of varying lengths e.g. imagecustomer names or item descriptions.

Exhibit A: the description column is wide enough to cope with most descriptions, but if you have an abnormally long description, the end of the text is lost.

How do you make sure that you can always fit the data onto the page without truncating any of it? Usually, one of two ways:

  1. Make the column wide enough to hold even your longest description without truncating.
  2. Make the font in that column small enough to fit the longest description in the width that you have.

Both of these methods have their drawbacks – either you make the column really wide and lose space for other columns, or make the font less readable for the majority of lines which fit inside the column anyway.

With RDL layouts, both of the below are additional solutions to the problem:

  1. Allow the row height to dynamically grow and the contents to break onto another line (the CanGrow property on the table row).
  2. Dynamically change the size of the font in the column depending on the length of the text – this was today’s solution.

Don’t forget that virtually every property on the RDL report can be calculated dynamically with an expression, including the FontSize property.

  • Select the description column of the table and find the FontSize property in the properties window.
  • Click the drop down arrow and choose Expression.
  • Enter an expression that calculates the font size that you want to set.

I used:

=IIf(Len(Fields!Description.Value) <= 30, “9pt”, “6pt”)

which in English translates to: “if the length of the description field is less than or equal to 30 characters, set the FontSize property to 9pt, otherwise set it to 6pt”.

It gave the following result. Insteadimage of cutting the end of the description off, the font is small enough to display all the text, but without making the text in all of the rows smaller at the same time.

It’s a trivial example, but it shows how we can control almost every aspect of the design and behaviour of the report dynamically.

Just one of the many benefits of RDL reports in Microsoft Dynamics NAV.

Leave a Reply