Run electronic report (ER) using menu item by x++ code in Dynamics 365 Finance and Operations - Part 3

Run electronic report (ER) using menu item by x++ code in Dynamics 365 Finance and Operations - Part 3

Suppose you need to generate a customer invoice in PDF format directly from a custom menu item in D365FO. Developers often face challenges in automating Electronic Reports (ER) in D365FO, especially when they need to trigger them outside the standard UI. In this guide, we will walk through how to invoke an ER report from a menu item using X++ code.

In the previous two parts, I explained the basics of Electronic Reporting (ER) and how to work with data model mappings. If you missed those sections, be sure to check out the links below.

Understand and configure electronic reporting data model in the Dynamics 365 Finance and Operations - Part 1

Working with Data Model Mapping in Electronic Reporting in Dynamics 365 Finance and Operations - Part 2

For demonstration purposes, I’ve created a simple vendor list report using Electronic Reporting (ER). Let me first walk you through the architecture of this report.

VendERModel (DATA Model)

VendERModelMapping (Model Mapping)

In the above setup, RunTimeParameters is an object added as the root, while VendTable represents a table. The RunTimeParameters object is mapped to our contract class, as illustrated in the below figure that will be provided later in this blog.

VendERFormat (ER Format)

After updating the status from Draft to Completed, proceed by clicking the Run button to execute the electronic report through the ER workspace interface.

The final output will appear as shown below.

So far, we have created our electronic report. Now, let’s move towards our main objective — calling this report using a menu item outside of the Electronic Reporting workspace.

To begin, open your development environment and set up a new project.

The first step is to create a contract class named ERVendorReportContract. Although this specific report doesn’t require parameters and could be called directly, we’ll create the contract class for learning purposes to understand how parameters can be added to a report.

The second step is to create a service class named ERVendorReportService.

The third step is to create a controller class and name it ERVendorReportController.

The fourth step is to create a menu item and associate it with the controller class you created earlier.

The fifth and final step is to add the menu item to the appropriate menu.

Once done, build the project and run the report.

Output:

Setup for the ER destination

In order to print the report, you must create and configure a new destination in the Electronic Reporting Destinations form. Without this setup, the report won't run from the menu item either. This is a mandatory step, so make sure to follow it accordingly.

Step 1: Navigate to the Electronic Reporting workspace and click on Electronic Reporting Destinations.

Step 2: Click the New button, then select VendERFormat in the Reference column.

Step 3: Specify the File component name and assign a Name for the destination. If you want the report to be generated in PDF format, make sure to check the Convert to PDF checkbox.

Note: If the File component name does not appear in the dropdown, it likely means the file name was not specified in the Format Designer. To fix this, set the file name there and change the status from Draft to Completed to apply your changes.

Happy Learning,

Syed Amir Ali.

To view or add a comment, sign in

Others also viewed

Explore topics