Reporting in Microsoft Dynamics NAV2018

Hi Team,

I have a report which I set filters but when I didn’t apply the filters and I preview the report. Nothing is show at my Getfilters. I want it to show “Report as at”.

Thanks.

From the last date to the present date

What is the “last date” ?

“Last date” means the first data in the table.

“Present date” means the date the report is running

i have a trade date as my filter but am nt applying the filter when I run the report. How can I default it to as the report runs.

"Report as at 08/29/2018"

Thanks

Assuming that “Report as at” should display “Report as at %1”, where %1 is the last date of your filter, and that the date filter has been set using the dataitem’s ReqFilterFields property for that field, then you can use GETRANGEMAX to get the last date. If no filter has been set then it will not work, so you need to check if a filter has been set with GetFIlter first.

And then remember to set this text in the OnPreReport trigger.

I have done the above process already but i didnt apply the filter when the request page is displayed. And I clicked preview button which show no “Report as at”. Is there way to display “Report as at” with no filter settled from request page run.

Do you mean that you want the report to set the filter if no filter has been set manually?

Yes, you can do that. Again use the OnPreReport trigger. If no filter was set, then yo can set it by code with something like SETRANGE(MyDateFilter,0D,TODAY)

CaptureReport2.PNG

Pls where am I placed the code. The code is for manually putting filter

OnPreReport()
CompanyInfo.GET;
CompanyInfo.CALCFIELDS(Picture);

FundAdminSetup.GET;
FundAdminSetup.CALCFIELDS("Watermark Portrait");

DateFilter := "Short Term Investment".GETFILTER("Current Value of Investment");

"Short Term Investment".SETRANGE(DateFilter,0D,TODAY);

OnPostReport()

"Short Term Investment".SETFILTER("Trade Date", DateFilter);

At Global Variable

Name Data Type
DateFilter Text

Its displayed error message “A field from a record variable is expected”

Record.Field

Customer.Name

Thanks

OnPreReport()
IF DateFilter = '' THEN 

  DateFilter := "Short Term Investment".GETFILTER("Current Value of Investment")

ELSE

  DateFilter := "Short Term Investment".SETRANGE("Trade Date",0D,TODAY);

While DateFilter is Text. I received error message "Text := VOID

That’s not the way to use SETRANGE!! It’s used to set a filter value, it doesn’t return a text value.

And you check if DateFilter is empty, but you do not set the datefilter until later. Also I don’t understand why you want to retrieves the DateFilter from the “Current Value of Investment” field, but set it to “Trade Date”? I assume that Current Value is a decimal field, and “Trade Date” is the date you need to use instead.

You need to say something like:

IF "Short Term Investment".GETFILTER("Trade Date") = '' THEN 
  "Short Term Investment".SETRANGE("Trade Date",0D,TODAY);

ReportToDate := "Short Term Investment".GETRANGEMAX("Trade Date");

This is if you only need the max date. Notice that the ReportToDate is a Date var, as GETRANGEMAX returns the max date. The reason you need to check that it has a filter, is that NAV will give you and error, if you use it without a filter applied to it. But also because you need the date.

IF "Short Term Investment".GETFILTER("Trade Date") = '' THEN BEGIN
  "Short Term Investment".SETRANGE("Trade Date",0D,TODAY);

ReportToDate := "Short Term Investment".GETRANGEMAX("Trade Date")

END ELSE

DateFilter := "Short Term Investment".GETFILTER("Trade Date");

That was the codes i wrote above. I added ReportToDate to Data Source and on the Layout.

When I run the report without filters, it shows report as at today which is fine but when i run the report with filters, it shows the filter range and report as at today.

How can I avoid it to not show report as at today when filter is selected. Thank you Mr Erik P

In which trigger did you write this code?

Try to run it with the debugger to see if it is executing the code too early or so.

The code was written in the OnPreReport(). Thanks