Report Usage Logging

Have you ever wanted to know which reports are actually used?
This is often a requirement when doing upgrade projects, cleaning up, or just monitoring what is in Top 10.
Here is how you setup central report logging.

Create a table for the log.
1

Create a Codeunit with 2 functions and 2 variables (1 is Temp).
Make this Codeunit SingleInstance (IMPORTANT)

2

AddReport(ReportID : Integer)
RepUsageTemp.INIT;
IF NOT RepUsageTemp.GET(ReportID, USERID) THEN BEGIN
 RepUsageTemp."Report ID" := ReportID;
 RepUsageTemp."User ID" := USERID;
 RepUsageTemp.INSERT;
END;
RepUsageTemp.Runs := RepUsageTemp.Runs + 1;
RepUsageTemp."Last Run" := TODAY;
RepUsageTemp.MODIFY;

SaveUsage()
IF RepUsageTemp.FINDSET THEN REPEAT
 IF NOT RepUsage.GET(RepUsageTemp."Report ID", USERID) THEN BEGIN
 RepUsage.INIT;
 RepUsage."Report ID" := RepUsageTemp."Report ID";
 RepUsage."User ID" := USERID;
 RepUsage.INSERT;
 END;
 RepUsage.Runs := RepUsage.Runs + RepUsageTemp.Runs;
 RepUsage."Last Run" := WORKDATE;
 RepUsage.MODIFY;
UNTIL RepUsageTemp.NEXT = 0;
RepUsageTemp.DELETEALL;

Pre NAV 2016
In Codeunit 1, add your Codeunit to the Global variables, and add code to these funtions.

FindPrinter(ReportID : Integer) : Text[250]

// Report Log
RepUsageMgt.AddReport(ReportID);

LogInEnd()

// Report Log
RepUsageMgt.SaveUsage;

NAV 2016
Instead of adding code to Codeunit 1, we use events.

Create 2 Functions with Subscriber Event in your Codeunit
34

Add the code to the functions instead of directly in Codeunit 1.

LOCAL [EventSubscriber] FindPrinter(ReportID : Integer;VAR PrinterName : Text[250])
RepUsageMgt.AddReport(ReportID);

LOCAL [EventSubscriber] SaveUsage()
RepUsageMgt.SaveUsage;

The collection of data happens to a temp table doing the session, and then written to table when the client closses. This is because when the FindPrinter function is called, NAV is not yet in a transactional state. So the SingleInstance codeunit makes the temp-table stay in client memory until close.
This work on both Classic and RTC.

This blog is enhanced from Mark Brummels post, to support Events.
https://dynamicsuser.net/nav/b/mark_brummel/posts/tip-20-save-report-usage

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s