preloader-matrix

Alfasith

Save the SSRS report as pdf or print it through code in Dynamic AX

Ax 2012 Reports (SSRS) Print Utilities
This article gives the examples, to print the reports of Dynamics Ax 2012 (SSRS Reports), in different ways.
1)Sending the Ax report through mail.
2)Save the report as file in local computer. (example covered to save the report as .pdf file)
Mail the report

static void myJobPrintReportMail(Args _args)
{
SrsReportRun                        reportRun;
Query                               query;
SRSReportPrintDestinationSettings   SRSReportPrintDestinationSettings;
SRSPrintDestinationSettings         srsPrintSettings;
;
delete_from SRSReportPrintDestinationSettings;
reportRun = new SRSReportRun();
reportRun.reportName(“Vend.Report”);  //<ReportName>.<DesignName>
// Set printersettings
srsPrintSettings = reportRun.printDestinationSettings();
srsPrintSettings.printMediumType(SRSPrintMediumType::Email);
srsPrintSettings.emailTo(“mail@gmail.com”);
srsPrintSettings.emailAttachmentFileFormat(SRSReportFileFormat::PDF);
srsPrintSettings.emailSubject(strfmt(‘vendor report – %1′, systemdateget()));
srsPrintSettings.pack();
reportRun.showDialog(false);
reportRun.init();
reportRun.run();
}
Save the Report To PDF File
static void myJobPrintReportPDF(Args _args)
{
SrsReportRun                        reportRun;
SRSPrintDestinationSettings         srsPrintSettings;
SRSReportPrintDestinationSettings   SRSReportPrintDestinationSettings;
;
delete_from SRSReportPrintDestinationSettings;
reportRun = new SRSReportRun();
reportRun.reportName(“Vend.Report”);  //<ReportName>.<DesignName>
// Set printersettings
srsPrintSettings = reportRun.printDestinationSettings();
srsPrintSettings.overwriteFile(true);
srsPrintSettings.printMediumType(SRSPrintMediumType::File);
srsPrintSettings.fileFormat(SRSReportFileFormat::PDF);
srsPrintSettings.fileName(“D:\Vendors.pdf”);
srsPrintSettings.pack();
reportRun.showDialog(false);
//reportRun.saveParameters();                         //For Report parameters
reportRun.init();
reportRun.run();
}
In case of Parameterized reports
If the report has parameters (Using Contract Class),
Use the following line, to read the parameters and save to the table called,SRSReportParameters
reportRun.saveParameters();
For the same parameters, provide the required values to run the report.
I have tried the example of Vendor Transactions report, with my customized version. This standard report has 4 parameters, have used same parameters and provided the values inSRSReportParameters table to run the report.
For clear idea, have a quick look in to the following picture.

Share on email
Share on facebook
Share on twitter
Share on linkedin
Share on pinterest