How to Send a Docentric SSRS Report to Multiple Print Destinations
For Print Management reports basically the Form setup form for setting multiple print destinations should be used.
Nevertheless, if you want to achieve some custom scenarios you can run a report from the code. The simplest way to print a report from the code to multiple print destinations is to run report from the code multiple times with different print settings. But this way the execution of logic for fetching the data needed for the report is repeated for each of report runs.
However, we can print the same report to more than one print destinations in the more effective way using Docentric AX APIs. Let’s say that we want to print a particular Customer invoice to multiple print destinations at once. It would be more efficient if we fetched the report data first, and then print the report to different print destinations. In order to achieve this scenario we should also assume that we registered Customer invoice as Docentric report and that we created a custom DSP (Data Source Provider) class for it.
1. Using the renderingCompleted event
The first way to print the same report to multiple print destinations in the more effective manner is to use the built-in SSRS renderingCompleted event. Take a look at the following job:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
static void printSalesInvoiceToMultiplePrintDest(Args _args) { SalesInvoiceController salesInvoiceController; SalesInvoiceContract salesInvoiceContract; Args args = new Args(); CustInvoiceJour custInvoiceJour; SalesInvoiceJournalPrint salesInvoiceJournalPrint; select custInvoiceJour where custInvoiceJour.SalesId != ''; args.record(custInvoiceJour); salesInvoiceController = new SalesInvoiceController(); // SalesInvoice.Report. salesInvoiceController.parmReportName( PrintMgmtDocType::construct(PrintMgmtDocumentType::SalesOrderInvoice).getDefaultReportFormat()); salesInvoiceContract = salesInvoiceController.parmReportContract().parmRdpContract(); salesInvoiceContract.parmRecordId(custInvoiceJour.RecId); salesInvoiceContract.parmCountryRegionISOCode(SysCountryRegionCode::countryInfo()); salesInvoiceController.parmArgs(args); salesInvoiceController.parmExecutionMode(SysOperationExecutionMode::Synchronous); // NOTE: We don't have to set salesInvoiceController.parmReportContract().parmPrintSettings().printMediumType() // and the corresponding print settings because only the report data will be executed at first, and // then in the renderingCompleted event the report will be dispatched to multiple print destinations. // Initalize SalesInvoiceJournalPrint class instance because there is no other way // NOT to use Print Management. salesInvoiceJournalPrint = SalesInvoiceJournalPrint::construct(); salesInvoiceJournalPrint.parmPrintFormletter(NoYes::Yes); salesInvoiceJournalPrint.parmUsePrintManagement(false); salesInvoiceJournalPrint.parmUseUserDefinedDestinations(true); salesInvoiceJournalPrint.parmPrinterSettingsFormLetter( salesInvoiceController.parmReportContract().parmPrintSettings().pack()); args.caller(salesInvoiceJournalPrint); args.parmEnumType(enumNum(PrintCopyOriginal)); args.parmEnum(PrintCopyOriginal::OriginalPrint); salesInvoiceController.renderingCompleted += eventhandler(SalesInvoiceReportDsProvider::renderingComplete); salesInvoiceController.parmShowDialog(false); salesInvoiceController.startOperation(); } |
In the following line of code we registered an event handler for the renderingCompleted event of SalesInvoiceController inheriting the SrsReportRunController base controller class:
1 2 |
salesInvoiceController.renderingCompleted += eventhandler(SalesInvoiceReportDsProvider::renderingComplete); |
In the custom Docentric DSP class (SalesInvoiceReportDsProvider) of Customer invoice report we need first to override the overrideReportRunSettings() method in order to tell Docentric AX Framework that only report data should be executed, without sending the report to any of print destinations.
1 2 3 4 5 6 7 8 9 10 11 12 |
public DocPlaceholderManager overrideReportRunSettings(DocReportRunContext _reportRunContext, boolean _replaceStandardPlaceholders = true) { DocPlaceholderManager placeHolderMng; placeHolderMng = super(_reportRunContext, _replaceStandardPlaceholders); // Set the flag to execute only the report data. _reportRunContext.parmExecuteOnlyData(true); return placeHolderMng; } |
And finally, here it is the event handler for the renderingCompleted event of the SalesInvoiceController controller class, where the report is dispatched to multiple print destinations:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
public static void renderingComplete(SrsReportRunController _sender, SrsRenderingCompletedEventArgs _eventArgs) { DocPrintDestSettingsPrinter printDestSettingsPrinter; DocPrintDestSettingsEmail printDestSettingsEmail; DocPrintDestSettingsFile printDestSettingsFile; DocPrintReportSettings printReportSettingsWithReportData; // Get the printReportSettings with the executed report data. DocReportSettingsExecutionInfo reportSettingsExecutionInfo = _eventArgs.parmReportExecutionInfo().parmReportSettingsExecutionInfo_DC(); printReportSettingsWithReportData = reportSettingsExecutionInfo.parmPrintReportSettings(); // Send the report to Screen by using already prepared data. DocGeneratorClient::printReportToScreen(printReportSettingsWithReportData); // Send the report to Printer by using already prepared data. printDestSettingsPrinter = DocPrintDestSettingsPrinter::constructWithPrinter('PrinterName'); DocGeneratorClient::printReportToPrinter( printReportSettingsWithReportData, printDestSettingsPrinter); // Send the report to Email by using already prepared data. printDestSettingsEmail = new DocPrintDestSettingsEmail(); printDestSettingsEmail.parmEmailTo('tom.cruise@gmail.com'); printDestSettingsEmail.parmEmailSubject('Invoice'); printDestSettingsEmail.parmEmailBody('Hello dear Tom'); printDestSettingsEmail.parmEmailAttachmentName('SalesInvoice.pdf'); printDestSettingsEmail.parmEmailAttachmentFileFormat(DocOutputFileFormat::PDF); DocGeneratorClient::printReportToEmail(printReportSettingsWithReportData, printDestSettingsEmail); // Send the report to File by using already prepared data. printDestSettingsFile = DocPrintDestSettingsFile::constructFullFilename(@'\\Shared\SalesInvoice.pdf'); printDestSettingsFile.parmOutputFileFormat(DocOutputFileFormat::PDF); DocGeneratorClient::printReportToFile(printReportSettingsWithReportData, printDestSettingsFile); } |
2. Preparing report data in advance
The second way to print the same report to multiple print destinations in the more effective manner is to use File as the target Print destination and XML as the target Output file format. This way only the run-time report Data Source Package (DDSP file) is generated and saved to file system. DDSP file can be then used as pre-pared report data source to execute report to different print destinations without fetching the same data again.
Take a look at the job where we generated only the report DDSP file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
static void printSalesInvoices_onlyData(Args _args) { CustInvoiceJour custInvoiceJour; MenuFunction salesInvoiceMenu; SalesInvoiceJournalPrint salesInvoiceJournalPrint; SRSPrintDestinationSettings srsPrintDestSettings = new SRSPrintDestinationSettings(); Args args = new Args(); select firstOnly custInvoiceJour where custInvoiceJour.SalesId != ''; // Select the File print destination with XML output format // because we want to print only the report data (actually the report DDSP file). srsPrintDestSettings.printMediumType(SRSPrintMediumType::File_DC); srsPrintDestSettings.parmFilePrintDestSettings_DC() .parmGeneratedDocFilename(@'Z:\SalesInvoice_@FIELD_InvoiceId@.xml'); srsPrintDestSettings.parmFilePrintDestSettings_DC() .parmOutputFileFormat(DocOutputFileFormat::XML); salesInvoiceJournalPrint = SalesInvoiceJournalPrint::construct(); salesInvoiceJournalPrint.parmPrintFormletter(NoYes::Yes); salesInvoiceJournalPrint.parmUsePrintManagement(false); salesInvoiceJournalPrint.parmUseUserDefinedDestinations(true); salesInvoiceJournalPrint.parmPrinterSettingsFormLetter(srsPrintDestSettings.pack()); args.caller(salesInvoiceJournalPrint); args.record(custInvoiceJour); // Run the report through the report menu item. salesInvoiceMenu = new MenuFunction(menuitemOutputStr(SalesInvoice), MenuItemType::Output); salesInvoiceMenu.run(args); } |
Once we have report DDSP file generated we can use it to print the report to multiple print destinations:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
static void printSalesInvoices_withPreparedData(Args _args) { str xmlDs; DocPrintReportSettings printReportSettingsWithReportData; DocPrintDestSettingsPrinter printDestSettingsPrinter; DocPrintDestSettingsEmail printDestSettingsEmail; DocPrintDestSettingsFile printDestSettingsFile; // Read the prepared in advance the report DDSP file from its file location. xmlDs = System.IO.File::ReadAllText(@'Z:\SalesInvoice_CIV-000001.xml'); // Construct the printReportSettings with the executed report data. printReportSettingsWithReportData = DocPrintReportSettings::construct(ssrsReportStr(SalesInvoice, Report), xmlDs); // Send the report to Screen by using already prepared data. DocGeneratorClient::printReportToScreen(printReportSettingsWithReportData); // Send the report to Printer by using already prepared data. printDestSettingsPrinter = DocPrintDestSettingsPrinter::constructWithPrinter('YourPrinterName'); DocGeneratorClient::printReportToPrinter( printReportSettingsWithReportData, printDestSettingsPrinter); // Send the report to Email by using already prepared data. printDestSettingsEmail = new DocPrintDestSettingsEmail(); printDestSettingsEmail.parmEmailTo('tom.cruise@gmail.com'); printDestSettingsEmail.parmEmailSubject('Invoice'); printDestSettingsEmail.parmEmailBody('Hello dear Tom'); printDestSettingsEmail.parmEmailAttachmentName('SalesInvoice_CIV-000001.pdf'); printDestSettingsEmail.parmEmailAttachmentFileFormat(DocOutputFileFormat::PDF); DocGeneratorClient::printReportToEmail(printReportSettingsWithReportData, printDestSettingsEmail); // Send the report to File by using already prepared data. printDestSettingsFile = DocPrintDestSettingsFile::constructFullFilename(@'Z:\SalesInvoice_CIV-000001.pdf'); printDestSettingsFile.parmOutputFileFormat(DocOutputFileFormat::PDF); DocGeneratorClient::printReportToFile(printReportSettingsWithReportData, printDestSettingsFile); } |
See also
How to Run a Docentric SSRS Report from Code >>
How to Dynamically Change Print Destination Settings >>
How to Use Placeholders in Print Destination Settings >>
SSRS Report Examples >>