Saturday, 28 December 2013

Cube report with parameter


Creating Cube report - with Parameter

In case of filtering cube records with input of user parameters we need to override Contract class in AX.
The parameter value which will be selected by user will not be in fully qualified parameter which is expected by MDX query. Hence we need to use UI Builder class where we implement conversion of user entered value to fully qualified format.
Let’s proceed with creating a report for APTrial by adding company as parameter.

Creation of Contract Class

Create a Contract Class for APTrialReport and reference the UIBuilder class and Report name.

Creation of UI Builder class

Components of UI Builder class
·         Class Declaration extending SrsReportDataContractUIBuilder.
·         Build method which builds dialog and  dialog controls.
·         getFromDialog() to get the value from dialog and set it to parameter.
·         postRun() to register all lookup methods.
·         processRangeValues()-To convert user entered value to fully qualified value.(customized)
·         Lookup methods.
Copy the code as per below screenshot.











Build method








getFromDialog











postRun




ProcessRangeValues
/// <summary>
/// This method is used to splits range values based on delimiter.
/// </summary>
/// <param name="_values">
/// Passing query criteria values.
/// </param>
/// <param name="_path">
/// fully qulified string for MDX values.
/// </param>
/// <param name="_delimiter">
/// Passing delimiter to seperate values.
/// </param>
/// <param name="_agencyId">
/// Passing agency code to seperate values.
/// </param>
/// <returns>
/// Returns splited values.
/// </returns>
private AifDetail processRangeValues(AifDetail _values, str _path, str _delimiter, str _agencyId = "")
{
    List            rangeParameterValuesList;
    ListEnumerator  listEnumerator;
    List            agencyList;
    ListEnumerator  agencyListEnumerator;
    AifDetail       rangeParameterValuesString;

    rangeParameterValuesString  = '';
    rangeParameterValuesList    = strSplit(_values, _delimiter);

    if (_agencyId != #Empty)
    {
        agencyList = strSplit(_agencyId, _delimiter);

        agencyListEnumerator = agencyList.getEnumerator();

        while (agencyListEnumerator.moveNext())
        {
            if (strLRTrim(agencyListEnumerator.current()) != '')
            {
                if (rangeParameterValuesList)
                {
                    listEnumerator = rangeParameterValuesList.getEnumerator();

                    while (listEnumerator.moveNext())
                    {
                        if (strLRTrim(listEnumerator.current()) != '')
                        {
                            rangeParameterValuesString += _path + strLRTrim(agencyListEnumerator.current()) +']&[' + strLRTrim(listEnumerator.current()) + ']' + _delimiter;
                        }
                    }
                }
            }
        }
    }
    else
    {
        if (rangeParameterValuesList)
        {
            listEnumerator = rangeParameterValuesList.getEnumerator();

            while (listEnumerator.moveNext())
            {
                if (strLRTrim(listEnumerator.current()) != '')
                {
                    rangeParameterValuesString += _path + strLRTrim(listEnumerator.current()) + ']' + _delimiter;
                }
            }
        }
    }

    return subStr(rangeParameterValuesString, 0, strLen(rangeParameterValuesString) - 1);
}

Lookup method












Compile the UIBuilder class and Contract class.

Create MDX Query with Parameter

Create a MDX query with AgencyMDX as parameter.
Click Execute button.

Click OK.

Create a precision design just as the report developed before. Deploy the report.


Create an output menu item to open the report.




No comments:

Post a Comment