Monday, 8 May 2023

Embedding Power BI reports into D365F&O

In order to view the custom Power BI reports in F&O, we need to embed the Power BI report file to specific desired location on form.

In this blog post, we will see the process of embedding a Power BI report file into D365F&O, enabling user to view and interact with custom Power BI reports within the application.

High level steps-

  1. Develop a Power BI report
  2. Create a resource file in Visual studio of Power BI report file (.pbix file)
  3. Embed the resource contents using controller class on form.
  4. Call a controller class from form control

We presume our custom Power BI report is developed and ready to embed. We need to create a resource object in F&O and add this .pbix file under that resource.



Once our resource file is ready, create a new controller class like below -
We need to use Power BI namespace (PBIPaaS) in our controller class, it provides the classes and utilities for working with Power BI reports in D365F&O.

using Microsoft.Dynamics.AX.Framework.Analytics.Deploy.PBIPaaS;

public class DemoPowerBIController extends PBIReportControllerBase

{

    // Name of the resource containing the content pack

    const str PowerBIContentPackName = 'PowerBIResource';

    // Name of content pack

    const str PowerBIReportName      = 'Demo';


    //Show or hide a filter pane on report

    protected boolean showFilterPane()

    {

        return true;

    }

    //Show or hide navigation pane on report

    protected boolean showNavContentPane()

    {

        return true;

    }

    public PBIReportRunParameters setupReportRunParams()

    {

        // populate and return the report run parameters for the session

        PBIReportRunParameters reportRunParams = new PBIReportRunParameters();

        reportRunParams.parmResourceName(PowerBIContentPackName);

        reportRunParams.parmReportName(PowerBIReportName);

        reportRunParams.parmShowFilterPane(this.showFilterPane());

        reportRunParams.parmShowNavContentPane(this.showNavContentPane());

        reportRunParams.parmPageName(this.pageName());

        reportRunParams.parmIsEmbedded(true);

        reportRunParams.parmApplyCompanyFilter(false);

        return reportRunParams;

    }

    public static void main(Args _args)

    {

        // initialize the controller object

        DemoPowerBIController controller = new DemoPowerBIController();

        controller.setupReportRunParams();

        controller.run(_args);

    }

    public void initializeReportControl(PBIReportRunParameters _reportParameters, FormGroupControl     _formGroupControl)

    {

        PBIReportHelper::initializeReportControlWithReportRunParams(_formGroupControl,                           _reportParameters);

    }

Now as a step number 4 - We need to call this controller class from Form control - Add a new group on form, under tab page a new group can be added. Call initializeReportControl() method from here.


[Control("TabPage")]
    class PowerBIDemoTabPage
    {
        public void pageActivated()
        {
            
            DemoPowerBIController controller = new DemoPowerBIController();
            controller.initializeReportControl(controller.setupReportRunParams(ResourceName,                                           ReportName), GroupNameUnderTheTabPage);
           
        }

    }

initializeReportControl() method is used to initialize the Power BI report control within the user interface. It takes the PBIReportRunParameters and a FormGroupControl as parameters, and calls the initializeReportControlWithReportRunParams() method from the PBIReportHelper class. 
So basically it will initialize the report control with the provided parameters.

Once you open a form in F&O, it will call the report and show the Power BI design on F&O UI.
Please note, in order to view your report you need to test it on higher environments than Tier 1.

basicFilters() is very useful method we can implement in the controller class which will open report file in F&O with initial filters like default company or specific user Id etc. 
It allow us to define and apply basic filters to the Power BI report before it is rendered to the D365F&O user interface. Which we may cover in separate blog.


Hope the current content is helpful!

No comments:

Post a Comment

Filtering Company-Specific Product Templates - SysRecordTmpTemplate lookup

Hi Techies - Recently I have come across a requirement where I needed to display product templates specific to a selected company for a give...