The AL developer preview is still evolving with frequent updates. Follow us on the Dynamics NAV Team Blog for the announcements.
SAVEASPDF Method (TestRequestPage)
Saves a report as an Adobe Acrobat (.pdf) file.
The TestRequestPage from which you want to test saving the report as a PDF file.
The path and filename to which the report is saved. The file name extension should be .pdf.
All filters and options that have been set on the TestRequestPage are respected in the saved report.
After you run this method, you cannot continue to interact with the TestRequestPage. If you want to continue to use the TestRequestPage variable, you must run a report again.
The following example shows the code for a test method to run a report and a request page handler method to test the request page. This example requires that you create the following:
A test codeunit called SaveAsPDF.
A test method in the test codeunit called TestSaveAsPDF.
A handler method of type RequestPageHandler called ReqPageHandler. This handler method has one parameter called RequestPage of Type TestRequestPage and Subtype Customer – Top 10 List. The RequestPage parameter is specified as VAR and is passed by reference to the handler method.
This example also requires that you create the following global variable of the SaveAsPDF codeunit.
//Test method: TestSaveAsPDF Filename := TEMPORARYPATH + 'MyRep.pdf'; MESSAGE(Filename); IF NOT FILE.ERASE(Filename) THEN ERROR('Cannot erase %1',Filename); REPORT.RUN(111); IF NOT FILE.EXISTS(Filename) THEN ERROR('File should exist!'); //Request Page Handler method RequestPage.Customer.SETFILTER("No.", '20000'); RequestPage.ChartType.VALUE('Pie chart'); RequestPage.SAVEASPDF(Filename);