Tuesday, September 24, 2013

Saving AX 2012 SSRS report in PDF in a folder



Just came across one of the common requirements of saving AX SSRS report in a specified folder. Here's is sample code for achieving this requirement:

1. In the controller class, modify the method 'preRunModifyContract'

public class myCustomReportController extends SrsReportRunController
{
    SRSPrintDestinationSettings printDestinationSetting;
}

protected void preRunModifyContract()
{
    FolderName      filePath = "C:\\xyz\\Customer Transactions\\"; //You may paramterize this also
    ;

    printDestinationSetting = new SRSPrintDestinationSettings();
    printDestinationSetting.printMediumType(SRSPrintMediumType::File);
    printDestinationSetting.fileName(
                            strFmt("%1%2_%3_%4_%5.pdf",
                                        filePath,
                                        date2str(systemDateGet(),321,2,0,2,0,2),    //Date
                                        CustTrans.Voucher,         //Voucher
                                        CustTrans.AccountNum,  //Customer
                                        timeNow()));                                
    printDestinationSetting.fileFormat(SRSReportFileFormat::PDF);
    printDestinationSetting.overwriteFile(true);
    this.parmReportContract().parmPrintSettings(printDestinationSetting);
}

This should override the print job settings for the custom report and will save the pdf file in the desired location. Please note that the client machine will not show the report on screen or print in printer since all the user settings will be overwritten by this code for that specific code.

No comments:

Post a Comment