Tuesday, 3 January 2017

Save SSRS report in PDF and send email attachemnt x++

public void SaveSSRStoPDF()
{
    SrsReportRunController              ssrsController = new SrsReportRunController();
    PayslipContract                 Contract = new PayslipContract();
    SRSPrintDestinationSettings         printerSettings;
    Filename                            ReportPath;
 
    while select HcmWorker
    {
         
            ReportPath = "C:\\"+ int2str(yearName) +"\\"+ int2str(monthName) +"\\"+ HcmWorker.PersonnelNumber +".pdf";
            ssrsController.parmReportName(ssrsReportStr(WorkerPayslip, Report));
            ssrsController.parmExecutionMode(SysOperationExecutionMode::Synchronous);
            ssrsController.parmShowDialog(false);
            Contract.parmPayGrpCode(PayGrpCode);
            Contract.parmYearName(yearName);
            Contract.parmHcmPersonnelNumberId(HcmWorker.PersonnelNumber);
            Contract.parmMonthName(monthName);
            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();
         // code to send email to employee with attached salary slip
            this.email(ReportPath);
            }
    }
}
For Email click here

No comments:

Post a Comment