RDP based SSRS report with Query (DateFrom, DateTo), AX classes

Contract class:
[DataContractAttribute]
class VKSalesQuotationDailyContract implements SysOperationValidatable
{
    TransDate        dateFrom;
    TransDate        dateTo;
    NoYes            showDetails;
    
    [
        DataMemberAttribute('dateFrom'),
        SysOperationLabelAttribute(literalStr("@SYS35369")),
        SysOperationControlVisibilityAttribute(true)
    ]
    public TransDate parmDateFrom(TransDate _dateFrom = dateFrom)
    {
        dateFrom = _dateFrom;
        return dateFrom;
    }

    [
        DataMemberAttribute('dateTo'),
        SysOperationLabelAttribute(literalStr("@SYS114982")),
        SysOperationControlVisibilityAttribute(true)
    ]
    public TransDate parmDateTo(TransDate _dateTo = dateTo)
    {
        dateTo = _dateTo;
        return dateTo;
    }

    [
        DataMemberAttribute('ShowDetails'),
        SysOperationLabelAttribute(literalStr("@SYS8811")),
        SysOperationControlVisibilityAttribute(true)
    ]
    public NoYes parmShowDetails(NoYes _showDetails = showDetails)
    {
        showDetails = _showDetails;
        return showDetails;
    }

    /// <summary>
    /// Validates the parameters.
    /// </summary>
    /// <returns>
    /// true if successful; otherwise, false.
    /// </returns>
    public boolean validate()
    {
        boolean isValid = true;

        if(!this.parmDateFrom())
        {
            error("Date from is mandatory");
            isValid = false;
        }
        if(this.parmDateFrom() && this.parmDateTo())
        {
            // Check whether FromDate is greater than ToDate or not
            if (this.parmDateFrom() > this.parmDateTo())
            {
                error("@SYS91020");
                isValid = false;
            }
        }
        return isValid;
    }

}
Controller class:
class VKSalesQuotationDailyController extends SrsReportRunController
{
    public static VKSalesQuotationDailyController construct()
    {
        return new VKSalesQuotationDailyController();
    }

    public static void main(Args _args)
    {
        VKSalesQuotationDailyController salesQuotationDailyController = VKSalesQuotationDailyController::construct();
        salesQuotationDailyController.parmReportName(ssrsReportStr(VKSalesQuotationDailyBooking, Report));
        salesQuotationDailyController.parmArgs(_args);
        salesQuotationDailyController.parmDialogCaption("Sales quotation daily bookings");
        salesQuotationDailyController.startOperation();
    }

    protected void prePromptModifyContract()
    {
        VKSalesQuotationDailyContract contract = this.parmReportContract().parmRdpContract();

        // Set the report design name.
        this.parmReportContract().parmReportName(ssrsReportStr(VKSalesQuotationDailyBooking, Report));
    }

}
Data provider class:
[
    // https://docs.microsoft.com/en-us/dynamicsax-2012/appuser-itpro/how-to-use-a-report-data-provider-class-in-a-report
    SRSReportQueryAttribute(queryStr(VKSalesQuotation)),
    SRSReportParameterAttribute(classstr(VKSalesQuotationDailyContract))
]
class VKSalesQuotationDailyDP extends SRSReportDataProviderPreProcessTempDB
{
    VKSalesQuotationDailyHeaderFooter    salesQuotationDailyHeaderFooter;
    VKSalesQuotationDaily                salesQuotationDaily;
    VKSalesQuotationDailyContract        contract;

    [SRSReportDataSetAttribute(tablestr(VKSalesQuotationDailyHeaderFooter))]
    public VKSalesQuotationDailyHeaderFooter getSalesQuotationDailyHeaderFooter()
    {
        select salesQuotationDailyHeaderFooter;
        return salesQuotationDailyHeaderFooter;
    }

    [SRSReportDataSetAttribute(tablestr(VKSalesQuotationDaily))]
    public VKSalesQuotationDaily getSalesQuotationDaily()
    {
        select salesQuotationDaily;
        return salesQuotationDaily;
    }

    /// <summary>
    /// Process report data.
    /// </summary>
    public void processReport()
    {
        contract = this.parmDataContract() as VKSalesQuotationDailyContract;
 
        // Populate report header / footer information
        this.populateSalesQuotationDailyHeaderFooter();
 
        // Populate data
        this.populateSalesQuotationDailyBookingInformation();
    }

    protected void populateSalesQuotationDailyHeaderFooter()
    {
        CompanyInfo    companyInfo = CompanyInfo::find();

        salesQuotationDailyHeaderFooter.CompanyName    = companyInfo.name();
        salesQuotationDailyHeaderFooter.DateFrom    = contract.parmDateFrom();
        salesQuotationDailyHeaderFooter.DateTo        = contract.parmDateTo();
        salesQuotationDailyHeaderFooter.ShowDetails    = contract.parmShowDetails();

        salesQuotationDailyHeaderFooter.insert();
    }

    protected void populateSalesQuotationDailyBookingInformation()
    {
        Query                    q = this.prepareQuery();
        QueryRun                qr;
        SalesQuotationTable        salesQuotationTable;
        SalesQuotationLine        salesQuotationLine;
        boolean                    showDetails = contract.parmShowDetails() ? true : false;

        qr = new QueryRun(q);
        while (qr.next())
        {
            salesQuotationTable    = qr.get(tableNum(SalesQuotationTable));
            salesQuotationLine    = qr.get(tableNum(SalesQuotationLine));

            salesQuotationDaily.CustAccount        = salesQuotationTable.CustAccount;
            salesQuotationDaily.CustName        = salesQuotationTable.customerName();
            salesQuotationDaily.CustPurpose        = salesQuotationTable.VKCustPurpose;
            salesQuotationDaily.WorkerSalesTaker= HcmWorker::find(salesQuotationTable.WorkerSalesTaker).PersonnelNumber;
            salesQuotationDaily.SalesAmount        = salesQuotationLine.LineAmount;

            if (showDetails)
            {
                salesQuotationDaily.ItemName    = salesQuotationLine.itemName();
                salesQuotationDaily.SalesQty    = salesQuotationLine.SalesQty;
            }
            salesQuotationDaily.insert();
        }
    }

    protected void insertSalesQuotationDaily(SalesAmount _salesAmount)
    {
        salesQuotationDaily.SalesAmount = _salesAmount;
        salesQuotationDaily.insert();
    }

    protected Query prepareQuery()
    {
        Query                    q = this.parmQuery();

        if (contract.parmDateFrom())
        {
            SrsReportHelper::addFromAndToDateRangeToQuery(
                q,
                contract.parmDateFrom(),
                contract.parmDateTo(),
                tableNum(SalesQuotationTable),
                fieldNum(SalesQuotationTable, CreatedDateTime));
        }

        return q;
    }

}
Output menu item:
Temporary table (VKSalesQuotationDaily. VKSalesQuotationDailyHeaderFooter) should be Table Type =  TempDB
Creating datasets at the SSRS report set Dynamic Filters property to True on all datasets from same data provider.

If changing the property to "True" you are facing with " The number of defined parameters is not equal to the number of cell definitions in the parameter panel." error, you will have to fix it manually (follow the link).
Report dialog:


Search

About

DaxOnline.org is free platform that allows you to quickly store and reuse snippets, notes, articles related to Dynamics AX.

Authors are allowed to set their own AdSense units.
Join us.

Blog Tags