Skip to main content
Unlisted page
This page is unlisted. Search engines will not index it, and only users having a direct link can access it.

Electronic Reporting (GER) from scratch part 2 Export an XML

In this Post we are going to see the step by step of how to configure everything needed for the export process to an XML file of the D365F&O tables data without writing a single line of code, using GER (Electronic Reporting). Note that this post and video are the second of the Electronic Reporting from scratch series, but they can be followed independently, however, I recommend you to check first the First Part (importing a text file)

D365FO Electronic Reporting (GER) From Scratch part 2: Export an XML file YouTube video

But, as I always like to do, this is not an empty post-link to the video, this is a shortcut version for lazy/hurried professionals. Well, actually here you are the different steps as a complement to the video, so you don’t have to go back and forward if you want to follow the post as a guide. The info here in the post might not be completed without the video, so if you have any doubt in a step, go and check the part of the video related with the one in the post, I put links in every step title, which will get you to the related part in the YouTube video, hope you enjoy it!

The Requirement

We want to export the information of our header and lines D365FO tables in Xml format using Electronic Reporting (GER).

D365FO Tables to import

The Electronic Reporting (GER) Export flow Overview

GER export flow overview

The Data Model (DM) will be our “Data contract”, I.E: the structure with the critical data we want to write in our XML. This information will be fulfilled by the Model Mapping to Model, who will query the tables and map them with the DM. Once the DM is populated it will, through the mapping between model and format, write the information into the actual XML. So the step by step would be:

Step 1: Create the Data Model.

We are going to create a simple Data Model, in the Electronic Reporting workspace:

Electronic Reporting main form

Click on Reporting Configurations, and create a new Root, that will be our Model.

Create new model

Go to Designer

And create the diferents nodes until you have a data model like in the following image, having the Model Root (Model), Header and Lines (Record list), and the Strings and Integer fields.

Create the nodes of your model

Step 2: Create the Datasource to Model mapping.

After finishing the Model structure, click on Map model to datasource, and create a new mapping, filling the mandatory fields and setting the direction To Model, because the information goes from the tables to the model:

Create a map between the D365FO Tables and your model

Click on designer, and we add root, selecting Table records from the first column, to add the tables we want to get the data from.

Add the table records

Now we have the tables as data sources, but no relation between them. (With FK relations, under the Header data source, surfing in the Relations we would find the lines table and we could use it directly). In this case we will need to filter the lines somehow, so the solution I made is to add a calculated field in the Header Data Source which will filter the data of the lines table using the Id of the record of the header.

First adding the calculated field under/inside Header level.

Add the calculated field

And editing the formula to put WHERE(Lines, Lines.HeaderId = @.Id).

Edit the Calculated Field formula

Save, go back to the previous form and complete the data model there.

Step 3: Create the Format And the Mapping with the model.

It’s time to give some format to our Data. Create a format, based on the recently created and completed model and set type to XML:

Go to the Designer and create a format with this structure:

Note that we’ve mapped it already inside the format designer. As we saw in the previous post, that could be done by creating a different Format to model mapping, but it is convenient for you to know both ways, because standard uses the two of them for its GERs. The map is direct, following the image above, but if you have problems with it, go and check the part of the video that goes through it.

We only have to save now, complete and Run our format! It will use the model and the mappings that we’ve created automatically, as there’s only one of each type.

Step 4: The Glory!

If there are no errors, a file should be generated with an XML like this

<?xml version="1.0" encoding="utf-8"?>
<XMLRoot>
<Headers>
<HeaderRecords>
<ID>01</ID>
<Name>Header 1</Name>
<Lines>
<LineRecord>
<LineStr>line 01</LineStr>
<LineInt>1</LineInt>
</LineRecord>
<LineRecord>
<LineStr>line02</LineStr>
<LineInt>2</LineInt>
</LineRecord>
<LineRecord>
<LineStr>line 03</LineStr>
<LineInt>3</LineInt>
</LineRecord>
</Lines>
</HeaderRecords>
<HeaderRecords>
<ID>02</ID>
<Name>Header 2</Name>
<Lines>
<LineRecord>
<LineStr>line 01</LineStr>
<LineInt>1</LineInt>
</LineRecord>
<LineRecord>
<LineStr>line04</LineStr>
<LineInt>4</LineInt>
</LineRecord>
</Lines>
</HeaderRecords>
</Headers>
</XMLRoot>