Sunday, July 19, 2015

Calling report design based on parameter selected without knowing contract class for AX 2012

Requirement: Calling report design based on parameter selected without knowing contract class.
Brief Steps:
1. Create a method in controller class linked with report which will select report design based on selected parameters.
2. Fetch report name in override method ‘preRunModifyContract’ with the help of method wrote in step 1 and frame report name to its contract class.
[Note: Before use any method for selecting report name we have to specify a report name in main method of controller class for default value.]
Elaborated steps:
Step 1: Create a method in controller class linked with report which will select report design based on selected parameters: 
Here, we have to pick report name based on selected inventory dimensions; below code is returning report design name ssrsReportStr(InventJournalTrans, Report_WL) when only ‘location’ and ‘warehouse’ was ticked at runtime and if any other is also ticked or if not match with this combination then, code is returning report design name ssrsReportStr(InventJournalTrans, Report)
private str getReportName()
{
    str reportNameLocal;

    if( this.parmReportContract().parmRdlContract().getValue('InventLocationId') && this.parmReportContract().parmRdlContract().getValue('WMSLocationId')       &&
        !(this.parmReportContract().parmRdlContract().getValue('ConfigId')       || this.parmReportContract().parmRdlContract().getValue('InventSiteId')        ||
        this.parmReportContract().parmRdlContract().getValue('InventSizeId')    || this.parmReportContract().parmRdlContract().getValue('InventColorId')        ||
        this.parmReportContract().parmRdlContract().getValue('InventStyleId')   || this.parmReportContract().parmRdlContract().getValue('InventProfileId_RU')   ||
        this.parmReportContract().parmRdlContract().getValue('InventOwnerId_RU')|| this.parmReportContract().parmRdlContract().getValue('InventBatchId')        ||
        this.parmReportContract().parmRdlContract().getValue('WMSPalletId')     || this.parmReportContract().parmRdlContract().getValue('InventSerialId')       ||
        this.parmReportContract().parmRdlContract().getValue('InventGTDId_RU')))
    {
        reportNameLocal =ssrsReportStr(InventJournalTrans, Report_WL);
    }
    else
    {
         reportNameLocal = ssrsReportStr(InventJournalTrans, Report);
    }
    return reportNameLocal;
}

Step 2: Fetch report name in override method ‘preRunModifyContract’ with the help of method wrote in step 1 and frame report name to its contract class.

/// <summary>
/// Changes the report contract before it runs the report.
/// </summary>
public void preRunModifyContract()
{
    boolean showLog = false;

    showLog = this.parmReportContract().parmRdlContract().getParameter(#ParameterShowLog).getValueTyped();
    this.processReportParameters(this.parmReportContract().parmQueryContracts().lookup(this.getFirstQueryContractKey()),
        showLog);
    // <GEELV>
    if (isInventJournalTrans_LV)
    {
        this.parmReportContract().parmReportName(ssrsReportStr(InventJournalTrans, Report_LV));
    }
    // </GEELV>
    // <GEERU>
    this.parmReportContract().parmRdlContract().getParameter(#parmISOCode).setValueTyped(SysCountryRegionCode::countryInfo());
    // </GEERU>

    this.parmReportContract().parmReportName(this.getReportName()); // Calling method and framing to its contract class
}

1 comment:

  1. :-) Thanks a lot. Its working. I have search on almost every blogs of AX. But i found the solution only here.

    ReplyDelete