Friday, 14 September 2018

Changing report design based on parameter value in X++ in AX

First, you need to create a controller class and override its preRunModifyContract() method. This method is commonly used for Modifying the query or setting the contract values that are hidden from the user on the dialog. Below is the sample code  

/// <summary>
///    The <c>HRKPIStatusReportController</c> class is the controller class for the <c>HRKPIStatusReport</c>
///    SRS report.
/// </summary>
class HRKPIStatusReportController extends SrsReportRunController
{

    public static void main(Args _args)
    {
        HRKPIStatusReportController controller = new HRKPIStatusReportController();
        controller.parmReportName(ssrsReportStr(HRKPIStatusReport, Summary));
        controller.parmArgs(_args);
        controller.startOperation();
    }

    protected void preRunModifyContract()
    {
        HRKPIStatusReportContract contract = this.parmReportContract().parmRdpContract() as HRKPIStatusReportContract;
       
        this.parmReportContract().parmReportName(this.getReportName(contract));
       
        super();
    }

    private str getReportName(HRKPIStatusReportContract _contract)
    {
        str reportNameLocal;

        if (_contract.parmReportDesign() == HRReportDesign::SummaryView)
        {
            reportNameLocal = ssrsReportStr(HRKPIStatusReport, Summary);
        }
        else
        {           
            reportNameLocal = ssrsReportStr(HRKPIStatusReport, Detail);
        }

        return reportNameLocal;
    }

}

Run AX report using X++

       Args                     args;      ReportRun          report;     salesLineProductPartProd salesLineProductPartProdLocal;     ;     ...