Mark Brummel - Author of Microsoft Dynamics NAV 2009 Application Design

Mark Brummel - Author of Microsoft Dynamics NAV 2009 Application Design

Tip #20 - Save Report Usage

This is a hot subject for a lot of companies using Navision. When was a report last executed, by whom and how many times.

The classic solution for this is to add code to every report to store this information in a table.

But it can be solved more generic...

The solution is in Codeunit 1. Here is a trigger FindPrinter that is executed prior to each report being printed. So what about implementing the solution here.

In order for this to work, we have to implement a trick, because when this code is executed, Navision is not yet in transaction state.

The trick is to save the report usage in a Temporary table first inside a SingleInstance codeunit.

What? Stick out tongue

Ok, let me explain this.

SingleInstance codeunits were introduced years ago. The benefit of this type of codeunits is that all variables are stored in client memory during the lifetime of the session. This includes temporary tables.

To activate this propery, just go in the codeunit's property window.

So what else do we need...

First of all the table to store data in. Off course you can make this as high tech as you want, but for this example we will store the Repord ID, the User ID, the number of runs and the last execution date.

The second thing we need is a management codeunit, the SingleInstance one.

This codeunit has two functions. One to populate/maintain the temporary table, and one to store the data in an actual table.

Remember to make the variable Temporary

Last change is to manage these functions from codeunit 1.

This is done in the FindPrinter and LogInEnd functions.

Remember that in both functions the RepUsageMgt codeunit is a LOCAL variable.

Enjoy...

Oh, and yes, this works in the Role Tailored Client as well.

Bookmark and Share

Comments

Peter said:

Nice tip, but the FindPrinter function is not used in the RTC for reports, unless they they are only in classic mode.

www.mibuso.com/.../viewtopic.php

It might have been changed in SP1, but I doubt it.

# December 1, 2009 1:07 PM

Marq said:

The second report in the print (50002) is a RTC report with RDLC layout printed from the RTC.

Yes, it really works.

# December 1, 2009 1:09 PM

Timo Lässer said:

Wow! Very very usefull tip!

I added this idea to my "Tools DB"!

Great work!

# December 1, 2009 1:23 PM

Marq said:

You're welcome. ;)

# December 1, 2009 1:30 PM

Peter said:

Great :-) I assume you are using SP1?

# December 1, 2009 1:46 PM

Marq said:

Yes, I do. I don't like the RTM version very much...

# December 1, 2009 1:47 PM

dakkon said:

Very cool trick, up until this point I had always gone with adding code to each report which is tedious to say the least.  I just wish the Navision folks would add a couple of methods to codeunit 1, like PreReportExecute and PostReportExecute, that if they existed would be called before and after running.  For that matter, it would be nice to have for other objects as well.  I suppose I might as well wish for a million dollars while I'm at it though.

# December 1, 2009 3:29 PM

FvErkel said:

Thanks! Very useful, we'll implement this immediately.

# December 1, 2009 5:36 PM

Marq said:

Good to hear Fred.

Can I send the invoice to the normal address?

:)

Just kidding...

# December 1, 2009 5:38 PM

FvErkel said:

Sure, we haven't moved :)

I think it's good that people make time to publish useful tips ... I mean, I feel a bit guilty that I haven't spend much time doing just that.

# December 1, 2009 5:52 PM

Bruce Kaplan said:

Thanks for the tip

# December 1, 2009 6:39 PM

Marq said:

Fred,

No problem. I might give you a call next couple of weeks. I am working on a new project where I can use your input.

Then we are even again. ;)

/Mark

# December 1, 2009 7:34 PM

David Singleton said:

Very useful.

# December 1, 2009 11:50 PM

Jan Pieter said:

Nice tip!

Does this work for processing only reports as well and for reports that only generate preview?

# December 2, 2009 11:25 AM

Marq said:

Yes, it works for preview.

No it does not work for processing only reports.

# December 2, 2009 12:21 PM

Reinhard said:

Hi Marq, great tip. I am using 4.0, and trying to implement it here. Great instructions. I did notice though that if you write:

Report.RUNMODAL(50090,TRUE,TRUE,Rec)

it will not call findPrinter. ie if you say systemPrinter  = TRUE it will not try to find a printer... any suggestions?

# December 3, 2009 3:34 AM

Marq said:

Reinhard,

In that case the solution will not work.

On the other hand, the solution is created for determining the value of ad-hoc reports. As you might know, a lot of customers have reports that are one created and never used. People leave the company and new people start, you know how it goes.

When you want to determine if a report can be overwritten the default procedure is to look in the usage table first and if not used, then renumber to a number that is outside the customers license. If it breaks or is nessesairy to use anyway you can easily put it back.

I know it is not a 100% covering solution but it helps.

Thank you for you feedback.

# December 3, 2009 10:42 AM

KLavin said:

Huh... I implemented the same thing over a year ago, but I didn't use the single instace... I stored it in an array with Report ID, datetime...

Then on CompanyClose(), LoginEnd() [making sure] OnGlobalModify() I dumped the contents of the Array into a table and reset it all for next time.

Nice one.

# December 10, 2009 11:00 PM

Navigate Into Success said:

“Best practices” is one of those beloved and hated concepts. There are people who just embrace “best

# September 4, 2010 10:43 AM

Mark Brummel - Author of Microsoft Dynamics NAV 2009 Application Design said:

Last week at Directions EMEA, Claus Lundstrom and I had a parallel session which was a pitty because

# May 16, 2011 11:06 PM

Mark Brummel - Microsoft Dynamics NAV Blog said:

Last week at Directions EMEA, Claus Lundstrom and I had a parallel session which was a pitty because

# May 17, 2011 12:07 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)