How to run and Save SSRS Report in Ax 2012


Description:-
Microsoft SQL Server Reporting Services (SSRS) is the primary reporting platform for Microsoft Dynamics AX. The default, predefined reports that are provided with Microsoft Dynamics AX run on the Reporting Services platform.

This topic guides you through the process of installing, deploying, and using these reports. This topic also provides information about how to create custom reports. 

Report Data Provider Class is an X++ class that is used to access and process data for a SSRS report. The RDP class processes the business logic based on a specified parameter and/or query and returns a dataset to the reporting services. In order to create a RDP class in AX, you have to extend that class with SRSReportDataProviderBase. This tells AX that this class will be used by reporting services to process the data.

Two important attributes are used in RDP classes:

1. SRSReportQueryAttribute: specifies which AOT query will be used in this report. If the RDP class uses an AOT query to process data, define this attribute at the beginning of the class.

2. SRSReportParameterAttribute: defines the data contract class that will be used by this report to prompt for parameter values. If the RDP class contains any parameters this define this attribute at the beginning of the class.

public str runAndSaveSSRSReportAX(PurchTable _purchTable)
{
    SrsReportRunController          ssrsController = new SrsReportRunController();
    PurchPurchaseOrderContract      Contract = new PurchPurchaseOrderContract();
    SRSPrintDestinationSettings     printerSettings;
    VendPurchOrderJour              VendPurchOrderJour;
    str                             ReportPath;

    select firstOnly VendPurchOrderJour order by VendPurchOrderJour.createdDateTime DESC
    where VendPurchOrderJour.PurchId == _PurchTable.PurchId;

    ReportPath = "C:\\" + _PurchTable.PurchId +".pdf";
    ssrsController.parmReportName(ssrsReportStr(PurchPurchaseOrder, Report));
    ssrsController.parmExecutionMode(SysOperationExecutionMode::Synchronous);
    ssrsController.parmShowDialog(false);
    Contract.parmRecordId(VendPurchOrderJour.RecId);
    ssrsController.parmReportContract().parmRdpContract(Contract);

    //link the printer settings to the controller
    printerSettings = ssrsController.parmReportContract().parmPrintSettings();
    //print to pdf and always overwrite if the file exists
    printerSettings.printMediumType(SRSPrintMediumType::File);
    printerSettings.fileFormat(SRSReportFileFormat::PDF);
    printerSettings.overwriteFile(true);
    printerSettings.fileName(@ReportPath);

    //run & save the report
    ssrsController.runReport();
    return ReportPath;
    // return the file location where pdf saved. we use this path to email and delete after email.
}

Related Posts

Previous
Next Post »

Thanks for comments.....