Please wait
Talk to Expert

How to pass the request page parameter when we run the report via code

Banner- Run the report via code

In Microsoft Dynamics 365 Business Central, reports are essential for data analysis, summaries, and decision-making. However, when running a report programmatically via code, we may have a case where we need to pass parameters of the request page through code & without user interaction. This post will guide you through the steps involved in passing parameters when running a report via AL code.

Step-by-Step: Passing Parameters to a Report in AL Code

1. Creating a Sample Report:
In this example, we have created report of Customer Ledger Entries with Start Date & End Date as a request page parameter.


2. Retrieving the XML String for Request Page Parameters:
To apply filters through code, we first need to retrieve the XML string containing the request page parameters. This string will allow us to pass the necessary inputs programmatically.

We’ve added a new action called “Get Report Request Page in XML” to generate the XML string. Below is how it works:

a) We use the RunRequestPage function to extract the request page parameters without actually running the report.

b) The RunRequestPage function returns an XML string containing all parameters set on the request page. This XML string will be used later to pass parameters through AL code.

Now, click the “Get Report Request Page in XML” action and enter the desired filters.

After clicking OK, the XML string will be generated. Below is a sample XML:

3. Retrieving the XML String for multiple Request Page Parameters and Dataitems:

We can also apply filters in multiple dataitem. We have added “Detailed Cust. Ledg. Entry” table’s dataitem in this report.

Let’s click on “Get Report Request Page in XML” action again and add request page filters along with dataitem filter.


We can modify retrieved XML string data as we want.

The retrieved XML string is as below:

<?xml version=”1.0″ standalone=”yes”?>
<ReportParameters name=”Request Page Parameter CLE” id=”50100″>
<Options>
<Field name=”StartDate”>2024-10-01</Field>
<Field name=”EndDate”>2024-10-31</Field>
</Options>
<DataItems>
<DataItem name=”CustLedgerEntry”>VERSION(1) SORTING(Field1)</DataItem>
<DataItem name=”DetailedCustLedgEntry”>VERSION(1) SORTING(Field1) WHERE(Field6=1(103001))</DataItem>
</DataItems>
</ReportParameters>

4. Triggering the Report via AL Code with Parameters:
We’ve created another action called “Run Report” to trigger the report using the XML string. Below is a snapshot showing how we pass the XML string as a label:

  • Use the XML string from the previous step to define the request page parameters.
  • Click the “Run Report” action, and the report will be generated with the specified filters.

The report will now download according to the Start Date and End Date set within the XML.

XML String:
<?xml version=”1.0″ standalone=”yes”?>
<ReportParameters name=”Request Page Parameter CLE” id=”50100″>
<Options>
<Field name=”StartDate”>2024-10-31</Field>
<Field name=”EndDate”>2024-10-31</Field>
</Options>
<DataItems>
<DataItem name=”CustLedgerEntry”>VERSION(1) SORTING(Field1)</DataItem>
</DataItems>
</ReportParameters>

Now, click on run report action and report will be downloaded according to the given filters in XML string.

This method offers flexibility for developers, enabling them to control how reports behave without user interaction.

If you’re curious about how we can assist you in reaching your goals, don’t hesitate to get in touch. Our dedicated team is ready to provide support every step of the way.

Let’s turn your vision into reality together!