65) Create a report using Contract, controller, and UI Builder for query based report.

 Scenario :- i have created a query based report and want to put the range only date but in the tbale the filed is date time. SO user have requirement that they want only a date filter not with the time,

So for this i create a contract class :- to validate the date 

UI Builder - to create a dialog

Controller class - to pass the query based report range


Step 1 : - Create a UI Builder class :-

/// <summary>

///    The <c>AvaAssetWorkorderHistoryReportUIBuilder</c> class is the UIBuilder class for the <c>AvaAssetWorkorderHistoryReport</c> report.

/// </summary>

[

    SrsReportNameAttribute('AvaAssetWorkorderHistoryReport.Report'),

    SysOperationContractProcessingAttribute(classstr(AvaAssetWorkorderHistoryReportUIBuilder), SysOperationDataContractProcessingMode::CreateUIBuilderForRootContractOnly)

]

class AvaAssetWorkorderHistoryReportUIBuilder extends SrsReportDataContractUIBuilder

{

    #define.parameterFromDate('FromDate')

    #define.parameterToDate('ToDate')

    #define.parameterAssetID('AssetID')

    DialogField dialogFromDate;

    DialogField dialogToDate;


    AvaAssetWorkorderHistoryReportContract contract;

    /// <summary>

    ///     Builds the dialog for the <c>AvaAssetWorkorderHistoryReport</c> SSRS report.

    /// </summary>

    public void build()

    {

        Dialog dialogLocal;

       


        dialogLocal = this.dialog();

        contract = this.getRdlContractInfo().dataContractObject() as AvaAssetWorkorderHistoryReportContract;


        dialogLocal.addGroup();

        dialogFromDate = dialogLocal.addFieldValue(extendedTypeStr(FromDate),DatetimeUtil::date(contract.getValue(#parameterFromDate)), "@SYS5209","");

        dialogToDate = dialogLocal.addFieldValue(extendedTypeStr(ToDate),DatetimeUtil::date(contract.getValue(#parameterToDate)), "@SYS14656");

        if (controller.parmArgs().record())

        {

            EntAssetObjectTable                 assetTable;

     

            assetTable = controller.parmArgs().record() as EntAssetObjectTable;

            

            if (assetTable)

            {

                contract.setValue(#parameterAssetID,assetTable.ObjectID);

            }

        }

    }


    /// <summary>

    ///    Transfers data from the dialog into the data contract object.

    /// </summary>

    public void getFromDialog()

    {

        contract.setValue(#parameterFromDate, DateTimeUtil::newDateTime(dialogFromDate.value(), 0));

        contract.setValue(#parameterToDate, DateTimeUtil::newDateTime(dialogToDate.value(),86399));

    }


}

=======================================================================


Step 3 - Create a controller class to pass the range and perform the action of report 


/// <summary>

///    The <c>AvaAssetWorkorderHistoryReportController</c> class starts the Asset workorder history report.

/// </summary>

class AvaAssetWorkorderHistoryReportController extends SrsReportRunController

{

    #define.ReportName ('AvaAssetWorkorderHistoryReport.Report')

    #define.parameterFromDate('FromDate')

    #define.parameterToDate('ToDate')

    #define.parameterAssetID('AssetID')



    /// <summary>

    ///    Override this method to change the report contract before running the report.

    /// </summary>

    protected void preRunModifyContract()

    {

        AvaAssetWorkorderHistoryReportContract    contract = this.parmReportContract().parmRdlContract() as AvaAssetWorkorderHistoryReportContract;

        Query               query = this.getFirstQuery();//this.parmReportContract().parmQueryContracts().lookup(this.getFirstQueryContractKey());

        FromDate            fromDate = contract.getParameter(#parameterFromDate).getValueTyped();//contract.getValue(#parameterFromDate);

        ToDate              toDate =  contract.getParameter(#parameterToDate).getValueTyped(); 

        EntAssetObjectID    assetID = contract.getParameter(#parameterAssetID).getValueTyped();


        

       // SysQuery::findOrCreateRange(query.dataSourceTable(tableNum(EntAssetWorkOrderTable)), fieldNum(EntAssetWorkOrderTable, ExpectedStart)).value(queryRange(fromDate, toDate));


      

    

        if (assetID)

         {

             // Modify the query contract based on fromDate & toDate.

             SrsReportHelper::addFromAndToDateRangeToQuery(query,

                                                           fromDate,

                                                           toDate,

                                                           tableNum(EntAssetWorkOrderTable),

                                                           fieldNum(EntAssetWorkOrderTable, ExpectedStart));


             // Modify the query contract based onAssetID.

             SrsReportHelper::addParameterValueRangeToQuery(query,

                                                            tableNum(EntAssetObjectTable),

                                                            fieldNum(EntAssetObjectTable, ObjectID),

                                                            assetID);

         }

    

        else

        {

            // Modify the query contract based on fromDate & toDate.

            SrsReportHelper::addFromAndToDateRangeToQuery(query,

                                                        fromDate,

                                                        toDate,

                                                        tableNum(EntAssetWorkOrderTable),

                                                        fieldNum(EntAssetWorkOrderTable, ExpectedStart));


   

        }

        super();

    }


    public static AvaAssetWorkorderHistoryReportController construct(Args _args)

    {

        AvaAssetWorkorderHistoryReportController controller = new AvaAssetWorkorderHistoryReportController();

        controller.parmReportName(#ReportName);

        controller.parmArgs(_args);

        return controller;

    }


    public static void main(Args args)

    {

        AvaAssetWorkorderHistoryReportController::construct(args).startOperation();

    }


}


================================================================


Step 4 - Create a action menu item and define the controller class and run the report

====================================================================

Image 1 :- 


Image 2 :- 3 manually parameter create :- 



=================================================================

Comments

Popular posts from this blog

Customization on Sales invoice Report in D365 F&O

75) COC - Create a coc of the table modified method

46) D365 FO: SHAREPOINT FILE UPLOAD USING X++