Dynamics 365 FO - Create SSRS Report with MVC - Microsoft Dynamics 365 Vietnam

Microsoft Dynamics 365 Vietnam

Song Nghia - Microsoft Dynamics 365 Vietnam

Breaking

Saturday, September 17, 2022

Dynamics 365 FO - Create SSRS Report with MVC

Dynamics 365 FO - Create SSRS Report with MVC

Nghia Song -  Microsoft Dynamics 365 Technical Consultant

Nghia Song

Tel - WhatsApp: +84967324794

Email: songnghia.uit@gmail.com


  1. Create a report with MVC

MVC need at least 2 two component:

Data Contract

Data Provider

But when you need to assign a default filter when running a report and change the layout design following with parameter, you need to create a Controller to control Data contract, to change report design.

In this practice, you will study and practice full of MVC components including:

Controller (Controller in MVC)

Data Contract (Controller in MVC)

Data Provider (Model in MVC)

SSRS Report (View in MVC)

Step

Screenshots

Description

0


Start Visual Studio using Run as administrator.


[DataContractAttribute]

class NVWBasicDataContract

{

    CustAccount custAccount;

    TransDate   fromDate;

    TransDate   toDate;


    [DataMemberAttribute('From Date') ]

    public TransDate parmFromDate(TransDate _fromDate = fromDate)

    {

        fromDate = _fromDate;

        return fromDate;

    }


    [DataMemberAttribute('To Date') ]

    public TransDate parmToDate(TransDate _toDate = toDate)

    {

        toDate = _toDate;

        return toDate;

    }


    [DataMemberAttribute('Customer Code') ]

    public CustAccount parmCustAccount(Description _custAccount = custAccount)

    {

        custAccount = _custAccount;

        return custAccount;

    }


}

Create one Class name: NVWBasicDataContract


public class NVWBasicController extends SrsReportRunController

{


    public static void main(Args _args)

    {

        NVWBasicController      controller = new NVWBasicController();

        ;

        controller.parmReportName("XXXX.YYY"); //You will edit XXX.YYY later

        controller.parmArgs(_args);

        controller.startOperation();

    }


    protected void prePromptModifyContract()

    {

        NVWBasicDataContract    contract;

        super();

        contract = new NVWBasicDataContract();


        contract = this.parmReportContract().parmRdpContract() as NVWBasicDataContract;


        contract.parmFromDate(today());

        contract.parmToDate(today());


        this.parmReportContract().parmRdpContract(contract);

    }


    protected void preRunModifyContract()

    {

        NVWBasicDataContract    contract;

        TransDate               fromDate;


        super();

        contract = new NVWBasicDataContract();


        contract = this.parmReportContract().parmRdpContract() as NVWBasicDataContract;

        fromDate = contract.parmFromDate();

    }

}

You must promote this class become controller in MVC; it means this class need extends from SrsReportRunController.


You have to enter extends SrsReportRunController in classDeclaration.


If you forget to enter extends SrsReportRunController, controller can not run, and this is normal class, not is controller class.


Controller will become entry point in AX client.


Entry point means menu item, so I need to create one menu item output to run controller


Creat new field BalanceAmount

Next step, this is important step when you develop SSRS report.


This important step is creating one or more Table tempdb for contain all records as final data result after query data.


Create one table and set TempDb as screenshot




Creat new field CustGroup


Creat new field CustName


Creat new field AccountNUm


[

    SRSReportParameterAttribute(classStr(NVWBasicDataContract))

]


public class NVWBasicDataProvider extends SRSReportDataProviderBase

{

    CustAccount     custAccount;

    TransDate       fromDate;

    TransDate       toDate;


    NVWBasicReportTmp   basicReportTmp;


    [

        SRSReportDataSetAttribute(tableStr(NVWBasicReportTmp))

    ]

    public NVWBasicReportTmp getReportTempDb()

    {

        select * from basicReportTmp;


        return basicReportTmp;

    }


    public void processReport()

    {

        NVWBasicDataContract    contract = new NVWBasicDataContract();

        CustTrans               custTrans;

    

        //Get value filter from contract

        contract    = this.parmDataContract() as NVWBasicDataContract;

        custAccount = contract.parmCustAccount();

        fromDate    = contract.parmFromDate();

        toDate      = contract.parmToDate();

        

        //Begin query data base on filter, you can use select statement or query object to get data

        ttsBegin;

        if(custAccount != "")

        {

            select AccountNum, sum(AmountMST)

                from custTrans

                group by AccountNum

                where custTrans.AccountNum == custAccount &&

                      custTrans.TransDate >= fromDate &&

                      custTrans.TransDate <= toDate;


            if(custTrans) //if custTrans different with Null record

            {

                basicReportTmp.clear();

                basicReportTmp.AccountNum       = custTrans.AccountNum;

                basicReportTmp.CustName         = CustTable::find(custTrans.AccountNum).name();

                basicReportTmp.CustGroup        = CustTable::find(custTrans.AccountNum).CustGroup;

                basicReportTmp.BalanceAmount    = custTrans.AmountMST;

                basicReportTmp.insert();

            }

        }

        else

        {

            while select AccountNum, sum(AmountMST)

                from custTrans

                group by AccountNum

                where custTrans.TransDate >= fromDate &&

                      custTrans.TransDate <= toDate

            {

                if(custTrans) //if custTrans different with Null record

                {

                    basicReportTmp.clear();

                    basicReportTmp.AccountNum       = custTrans.AccountNum;

                    basicReportTmp.CustName         = CustTable::find(custTrans.AccountNum).name();

                    basicReportTmp.CustGroup        = CustTable::find(custTrans.AccountNum).CustGroup;

                    basicReportTmp.BalanceAmount    = custTrans.AmountMST;

                    basicReportTmp.insert();

                }

            }

        }

        ttsCommit;

    }

}

Create new class for DataProvider


NVWBasicDataProvider


Create new SSRS Report Design


Create new Data Set with Data Source Type os Report Data Provider


Select the data provider for report


Select table and fieds in data provider




Create design of report


Create Page Header and Footer


Insert new textbox display company name in header



Design and add Expression to display data




Insert new table in body to display data



Select field data in table 




Insert text box display day print in footer


Select expression to display day print


   public static void main(Args _args)

    {

        NVWBasicController      controller = new NVWBasicController();

        ;

        controller.parmReportName("Report.ReportDesign"); //You will edit XXX.YYY later

        controller.parmArgs(_args);

        controller.startOperation();

    }

Modify value of report and design of report to controller


Deploy report


Add menu action to menu and run report



Build and sync project



View the design of report and report data

Next: Dynamics 365 FO - Customize with extensions and overlayering - Part 1 https://www.songnghia.com/2022/09/dynamics-365-fo-customize-with.html

No comments:

Post a Comment