Friday 10 November 2017

Dynamics NAV - How to run a Report based on a set of records in CAL Code


Hello, during one of my projects, i realised the need to run a certain report based on a set of records.
In other wards, before i execute the report, i need to filter out the data. The result set in the filter is what i display in the report. All using code.
You might also need to do the same thing. It's simple just follow this.
Filter the table records that you want displayed on the report
CAL gives you a number of functions that allow you filter records in a table. Some of these include
SETRANGE, SETFILTER among others.
Use your preferred method to filter the records you want

Execute the report using the function call
REPORT.RUNMODAL(Number [, ReqWindow] [, SystemPrinter] [, Record])
The function takes on 4 values.
The first value is the OBJECT ID (Report Object ID) which is an integer
The second value is a boolean specifying whether to display the report request page
The third value  is a boolean specifying whether to use the system default printer - 
specified in printer settings of your PC
The fourth value is record (The table you filtered on)
Here is an example

Customer.RESET;// (Customer is a record of table 18)
Customer.SETRANGE("No.",10000);
IF Customer.FINDFIRST THEN
REPORT.RUNMODAL(50053, TRUE,TRUE,Customer);

Alternatively
CLEAR(Report50053);
Customer.SETRANGE("No.",Rec."No.");
Report50053.SETTABLEVIEW(Shipment);
Report50053.RUN;
The above code will execute report 50053 based on customer whose No. is 10000
A request page will be displayed as well
For more information on this topic click here

I would like to hear your thoughts
Please leave a comment and follow for more.
Good luck





No comments:

Post a Comment