Report Inspector 2.0 – How to Export Your Report Dataset as Excel, XML or Windows client Style

Report Inspector 2.0 – How to Export Your Report Dataset as Excel, XML or Windows client Style

Today’s post covers some programming that is not of my own making. My colleague Andreas Rascher has built a damn cool functionality that allows you to export the dataset of RDLC reports in different formats. Since we think the functionality is extremely useful, we didn’t want to keep it from you.

You may remember the Mini Report Inspector by Steven Renders. With it it was possible to export the dataset of a report as XML. The Report Inspector by Andreas also gives you the possibility to export the dataset in the old Windows client DataSet_Result way – as Excel file or XML! How cool is that? A lot of black magic was used to make this possible. If you don’t know what the difference is – I’ll show you the exact details further down in the blog post.

So this is the big strong brother of the Mini Report Inspector – the Report Inspector on steroids if you will. He would always protect his little brother. I see this as a cool community effort. Steven has laid the foundation with his Mini Report Inspector, Andreas has stepped it up a notch and I’m the busy writer. If that’s not what a community is all about, then I don’t know what is.

What Does the Report Inspector Do

The Report Inspector enables you to export informations about the report DataSet in 3 different formats:

  • ResultSet XML – The Dataset format known from the windows client as XML File
  • SaveAsXML – The Result from Report.SaveAsxml
  • Excel – The Dataset format known from the windows client as Excel File

This is not all. You can even extend the Report Layout Selection page and export the dataset for all the RDLC Layouts without having to insert the logic into the reports.

How to Use It in Your Report

For my demonstration I will use a copy of the Standard – Sales Invoice (1306) and Business Central 17.

First, copy the codeunit from Andreas’ Github and add it to your project.

Second, add four new global variables to the report. You can also copy the code from the report in Andreas’ Github project.

    var
        DataSetExportHelper: Codeunit DataSetExportHelper;
        ExportDatasetOptions: Option "Select an export format","ResultSet XML","ReportSaveAs XML","Excel";
        [InDataSet]
        IsRunRequestPageMode: Boolean;
        ExportDataSet: Boolean;

Third, add two new fields to the request page:

 field(ExportDataSetCtrl; ExportDataSet)
                    {
                        Caption = 'Export DataSet';
                        ApplicationArea = all;
                        Visible = not IsRunRequestPageMode;
                        trigger OnValidate()
                        begin
                            DataSetExportHelper.OpenRequestPageForDatasetExport(CurrReport.ObjectId(false));
                            ExportDataSet := false;
                        end;
                    }
                    field(DataSetExportOptionsCtrl; ExportDatasetOptions)
                    {
                        Caption = 'Export Dataset as';
                        ShowCaption = false;
                        ApplicationArea = All;
                        Visible = IsRunRequestPageMode;
                    }

Fourth, add this line of code to the OnOpenPage trigger.

 IsRunRequestPageMode := DataSetExportHelper.GetRunReqPageMode(); 

That’s it. Now let’s run the report. When the request page opens, you will see an option “Export DataSet”. Click on it.

If you click on it, a new request page opens. Here you have to select an export format.

If you select the option ResultSet XML, the dataset will be exported in the old windows client style. Please make sure that the filter is still correctly set. Otherwise, you may run into errors.

Press Ok and enjoy the result, pun intended. You may not see it in the screenshot, but every <Result> contains the fields from every DataItem with a value in it. So one <Result> contains the values from our “Sales Invoice Header” as well as all Data Items below it like “Sales Invoice Line” etc.

Let’s try to export the dataset in the “new” XML format. Select “ReportSaveAs XML” and press OK.

This is how it looks:

Last but not least, the Excel option is already waiting for us. Select it and click OK.

The result:

How to Use It in Your Report Layout Selection

You think that’s all? It is not. You can even add a PageAction to your Report Layout Selection that let’s you export the dataset for every report without having to insert the functionality into the reports. Use this if you do not want to insert the functionality into every report.

Copy the code from this PageExtension in the repository and that’s it.

Limitations

Only available for Reports with integrated RDLC Layout. The data is collected by parsing the SaveAsXML File (Columns) and the RLDC File (Order of Columns). Not all Metadata is available to recreate a complete DataSet.xml like in the windows client (e.g. XSD Section).
CurrRerport.PageNo is not being exported when using SaveAsXML – more a feature than a bug. 😉

Source Code

The source code can be found on this Github repository.

23 thoughts on “Report Inspector 2.0 – How to Export Your Report Dataset as Excel, XML or Windows client Style

Reposts

  • Gregory Alekseev
  • David Machanick
  • Gerardo Rentería
  • Natalie "BC Docs Librarian" Karolak 🔍

Mentions

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: