How to create SSRS Report in ax 2012

Description:-
 
A Report data provider class is commonly known as RDP. RDP is the data source type which is available when we add a new dataset to the report in Visual Studio. RDP is a class which resides inside AX and executes the business logic, processes the data, and returns a dataset which is rendered in the report.

A Report data provider class should be ideally used in the following cases:

We cannot directly use a query to access the data from the database
The data has to prepare on the basis of business logic

To define a Report data provider class, we use the following syntax:

[SRSReportParameterAttribute(classStr(SalesInvoiceRegisterContract))]
class SalesInvoiceRegisterDp extends SRSReportDataProviderBase
{
    CustAccount                  _CustAccount;
    BaseDate                     _FromDate,_ToDate;
    SalesInvoiceRegisterContract _Contract;
    SalesInvoiceRegistertmp     SalesInvoiceRegistertmp;
}

Now create table return method in data provider class like below.

[SRSReportDataSetAttribute("SalesInvoiceRegistertmp")]
public SalesInvoiceRegistertmp getSalesInvoiceRegistertmp()
{
    select * from SalesInvoiceRegistertmp;//temp table
    return SalesInvoiceRegistertmp;
}

Now create ProcessReport method in Data Provider class.

public void processReport()
{
    _Contract                   = this.parmDataContract();

    _FromDate                   = _Contract.ParmFromDate();
    _ToDate                     = _Contract.ParmToDate();
    _CustAccount                = _Contract.ParmCustAccount();
}

Report contract class

Report contracts in AX 2012 are used for defining parameters to the SSRS report. We can define any number of parameters using X++ statements of any data type, which can be passed on to the RDP class. And then, we can use the same contracts to query data from the database engine which will decrease an overhead on execution of a query in SQL.

To define a Report contract class we use the following syntax:

[DataContractAttribute]
class SalesInvoiceRegisterContract implements SysOperationValidatable
{
    BaseDate                    FromDate,ToDate;
    CustAccount                 CustAccount;
}

Now create customer account parameter method in contract class.

[DataMemberAttribute("Customer"),SysOperationLabelAttribute("Customer"),SysOperationDisplayOrderAttribute('1')]
public CustAccount ParmCustAccount(CustAccount _CustAccount = CustAccount)
{
    CustAccount = _CustAccount;
    return CustAccount;
}

Now create from date and to date method In contract class.

[DataMemberAttribute('FromDate'), SysOperationLabelAttribute('From Date'), SysOperationDisplayOrderAttribute("2")]
Public BaseDate ParmFromDate(BaseDate _FromDate = FromDate)
{
    FromDate = _FromDate;
    return FromDate;
}

[DataMemberAttribute('ToDate'), SysOperationLabelAttribute('To Date'), SysOperationDisplayOrderAttribute("3")]
Public BaseDate ParmToDate(BaseDate _ToDate = ToDate)
{
    ToDate = _ToDate;
    return ToDate;
}

Now create validate method in contract class for validate report parameter in contract class like below.

public boolean validate()
{
    boolean isValid = true;

    if (!FromDate)
    {
        isValid = checkFailed(strFmt("@SYS84753", "@SYS180311"));
    }
    if (!ToDate)
    {
        isValid = checkFailed(strFmt("@SYS84753", "@SYS180217"));
    }
    if(FromDate && ToDate)
    {
        if (FromDate > ToDate)
        {
            isValid = checkFailed(strFmt("@SYS300457", date2StrUsr(FromDate, DateFlags::FormatAll), date2StrUsr(ToDate, DateFlags::FormatAll)));
        }
    }
    return isValid;
}

Now in Visual Studio add the following

Add Report
Add Data Set
       Set the Properties for that Data Set.
       Set the Parameters you want to set blank value for ItemId Parameters

      Allow blank = true
      Null-able = true

Add Precision Design
Deployed SSRS Report and Run it.

Related Posts

Previous
Next Post »

Thanks for comments.....