How to attach the PowerBI report to Dynamics 365 FnO and Run it.

Sharing insights into my recent development, I successfully integrated Power BI reports into the Dynamics 365 menu, addressing specific client needs for seamless access and enhancing the overall user experience."

Requirement:

User has a powerbi report pbix file which is already published. Now he wants to open the powerbi report from dynamics 365 FnO.

Solution:

Step1 (Creation of Resource file and placing pbix file in path):

Create an Resource file(XML) and place the file in the AOS path. In our case the path is: “J:\AosService\PackagesLocalDirectory\CustomModel\CustomModel\AxResource”





Here is the Resource file format:

<?xml version="1.0" encoding="UTF-8"?>

<AxResourcexmlns:i="http://www.w3.org/2001/XMLSchema-instance"><Name>DemoProjectedStockPBIX</Name><FileName>DemoProjectedStock.pbix</FileName><RelativeUriInModelStore>CustomModel\CustomModel\AxResource\ResourceContent\PowerBIReport\DemoProjectedStock.pbix</RelativeUriInModelStore><TypeOfResource>PowerBIReport</TypeOfResource></AxResource>

Name: This is name or identifier associated with the Power BI report.

FileName: This provides the actual file name of the Power BI report, suggesting it's named "DemoProjectedStock.pbix."

RelativeUriInModelStore: This is URI (Uniform Resource Identifier) indicating the location of the Power BI report within the model store structure. It provides the path to the report file.

TypeOfResource: PowerBIReport Indicates the type of resource, confirming that it is a Power BI report.

Place the Power BI report(pbix) file in the following location: J:\AosService\PackagesLocalDirectory\CustomModel\CustomModel\AxResource\ResourceContent\PowerBIReport





Step 2 (Create a controller class):

The class extends PBIReportControllerBase, which suggests that it's designed to work with the Power BI integration framework in D365FO.

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

class DmoPowerBIReportController extends PBIReportControllerBase
{
    // Name of the resource containing the content pack
    const str PowerBIContentPackName = 'DmoProjectedStockPBIX';

    // Name of content pack
    const str PowerBIReportName      = 'Projected Stock';

    protected boolean showFilterPane()
    {
        return true;
    }

    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
        DmoPowerBIReportController controller = new DmoPowerBIReportController();
        controller.setupReportRunParams();
        controller.run(_args);
    }

    /// <summary>
    /// Initialize the runtime properties required by report viewer control.
    /// </summary>
    /// <param name = "_reportParameters">The report parameters.</param>
    /// <param name = "_formGroupControl">The form group control to apply report viewer control.</param>
    public void initializeReportControl(PBIReportRunParameters _reportParameters, FormGroupControl _formGroupControl)
    {
        PBIReportHelper::initializeReportControlWithReportRunParams(_formGroupControl, _reportParameters);
    }

}
Step 3 (Create a from):

In our case we created a simple details w/standard tab pattern









Created an initialized method on PowerBIReportGroup control

[Form]
public class DmoProjectedStockPbix extends FormRun
{
    [Control("Group")]
    class PowerBIReportGroup
    {
        protected void initialize()
        {
            DmoPowerBIReportController controller = new DmoPowerBIReportController();
            PBIReportRunParameters reportParameters = controller.setupReportRunParams();
            controller.initializeReportControl(reportParameters, PowerBIReportGroup);

            super();
        }

    }

}


Step 4:

Create a display menu item to open the form and assign the menu item to menu.


Thanks for reading!!!


How to attach the PowerBI report to Dynamics 365 FnO and Run it.

Sharing insights into my recent development, I successfully integrated Power BI reports into the Dynamics 365 menu, addressing specific clie...