Advertisements

Usage of RUNREQUESTPAGE, EXECUTE, SAVEAS and PRINT function of Reports Object

Today we will discuss usage of RUNREQUESTPAGE, EXECUTE, SAVEAS and PRINT function of Report Object.

You will be using RUNREQUESTPAGE function to run the request page of desired Report.

We will save the value of Parameters in Table for further use. For this we will require to create a table with below structure let name it as Report Request Parameters.

Create a table called Report Request Parameters that has the following fields.

Field Name Data Type Length
ReportId Integer
UserId Code 100
Parameters BLOB

ReportParameter-1

Then we will use these value with

EXECUTE – To preview the report.

SAVEAS – To save it as pdf file.

PRINT – To print the Report.

To continue with our demo we will require to create a codeunit, let’s name it as Using Report Functions.

We will add the following variables in the C/AL Globals window.

Variable name DataType Subtype Length
ReportParameters Record Report Request Parameters
XmlParameters Text
OStream OutStream
IStream InStream
CurrentUser Code 100
Content File
TempFileName Text

ReportParameter-2

Now we will add the following code to the OnRun trigger of the codeunit.

We will be taking Report 206 as an example for this demo.

ReportParameter-3

You can copy below code for your demo.

// Use the REPORT.RUNREQUESTPAGE function to run the request page to get report parameters

XmlParameters := REPORT.RUNREQUESTPAGE(206);

CurrentUser := USERID;

// Save the request page parameters to the database table

WITH ReportParameters DO BEGIN

// Cleanup

     IF GET(206,CurrentUser) THEN

DELETE;

SETAUTOCALCFIELDS(Parameters);

ReportId := 206;

UserId := CurrentUser;

Parameters.CREATEOUTSTREAM(OStream,TEXTENCODING::UTF8);

MESSAGE(XmlParameters);

OStream.WRITETEXT(XmlParameters);

INSERT;

END;

CLEAR(ReportParameters);

XmlParameters := ”;

// Read the request page parameters from the database table

WITH ReportParameters DO BEGIN

SETAUTOCALCFIELDS(Parameters);

GET(206,CurrentUser);

Parameters.CREATEINSTREAM(IStream,TEXTENCODING::UTF8);

IStream.READTEXT(XmlParameters);

END;

// Use the REPORT.SAVEAS function to save the report as a PDF file

Content.CREATE(‘TestFile.pdf’);

Content.CREATEOUTSTREAM(OStream);

REPORT.SAVEAS(206,XmlParameters,REPORTFORMAT::Pdf,OStream);

Content.CLOSE;

// Use the REPORT.EXECUTE function to preview the report

REPORT.EXECUTE(206,XmlParameters);

// Use the REPORT.Print function to print the report

REPORT.PRINT(206,XmlParameters);

We are done, definitely this will help you doing some useful stuffs in your projects.

Run the Codeunit and see the output. You will get three output

a) Report Output will be saved as pdf, you can specify your custom path to save the file to specified location.

b) Report Print Preview

c) Report will be send for Printing

Advertisements

Comments are closed.

Important

Most of the contents you find in this blog will be either inherited from MSDN or Navision Developer IT Pro Help. Some places images are also directly taken from these sites. Purpose is simple to try those stuffs and re-produce adding few things as per my understanding to make easy understanding for others and quick reference.

Here nothing under my own brand or authorship of the content. At any point of time we are just promoting Microsoft stuffs nothing personnel with same.

Hope stuffs used here will not violate any copyright agreement with them. In case by mistake or in-intestinally it happens and the Microsoft feels these should not be used Microsoft have full right to inform me about same and will be glad to take down any such content which may be violating the norms.

Purpose is to promote Navision and share with community.

FB Profile

Like FB Page

%d bloggers like this: