Save SSRS Reports as a PDF from Dynamics AX 2012

In recent work with a client where they learned to automatically attach a file through code, in Dynamics AX 2012, the customer also wanted to have the report saved as PDF when it was printing the report.

In this case it was a proforma invoice.

In order to do so I used the info from this blog post to modify the  outputReport() method of the SalesInvoiceController  class so the report is saved when the user prints it.

The code snippet below was added at the very end of the “`outputReport()“` method:

// 28-Mar-2013 RvB --> When proforma invoice, save PFD copy and 
attach to order
formLetterReport.getCurrentPrintSetting().parmPrintJobSettings().printMediumType(srsPrintMediumType::File);
formLetterReport.getCurrentPrintSetting().parmPrintJobSettings().fileFormat(SRSReportfileFormat::PDF);

dateStr     = strFmt("%1-%2-%3-%4", DateTimeUtil::month(DateTimeUtil::utcNow()),
                                    DateTimeUtil::day(DateTimeUtil::utcNow()),
                                    DateTimeUtil::hour(DateTimeUtil::utcNow()), 
                                    DateTimeUtil::minute(DateTimeUtil::utcNow()));
fcFileName  = strFmt("%1\\\\%2_%3_.pdf",DocuParameters::find().ArchivePath, custInvoiceJour.SalesId, dateStr);

formLetterReport.getCurrentPrintSetting().parmPrintJobSettings().fileName(fcFileName);

//Save the PDF
super();

//Now attach the file to the order
salesTable = salesTable::find(custInvoiceJour.SalesId) ;

if (salesTable)
{
    //Add the PDF to document handling
    rvbAttachDoc::attachFile(salesTable, fcFileName, 'File');
}
// 28-Mar-2013 RvB  <--

Microsoft Dynamics ERP and CRM Partner, New York, NY for Microsoft Dynamics AX 2012 (Axapta)
Source: coderscove
By | 2017-10-13T19:48:03+00:00 April 29th, 2013|Tech Tips|0 Comments
Alternative Text

Contributor: AKA Enterprise Solutions

AKA is comprised of professionals with deep experience in business, technology, and their respective industries. Our team members regularly share their knowledge and expertise through blog articles. We hope you find them helpful, and we welcome your comments.

Leave A Comment