How to Run a Docentric SSRS Report from Code
You can print a Docentric SSRS report from X++ using the standard approach of running an SSRS report from the code. The only difference is that you have to additionally specify that the target print destination is Docentric Screen/File/Email/Printer/Print Archive and set the corresponding Docentric print destination settings.
In the following example we are going to send the built-in SSRS report – Birthdays (located in Company/Human resources/Reports/Workers -> Birthdays) to Docentric File print destination.
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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
static void runDocentricSrsReportFromCode(Args _args) { SrsReportRunController controller; HcmBirthdayContract rdpContract; SRSPrintDestinationSettings srsPrintDestSettings; DocPrintDestSettingsFile filePrintDestSettings; // Construct a new SrsReportRunController instance. controller = new SrsReportRunController(); // Set the SSRS Report Design to run. controller.parmReportName(ssrsReportStr(HcmBirthday, Report)); // Construct a new RDP contract instance. rdpContract = new HcmBirthdayContract(); // Explicitly set all required report parameters. rdpContract.parmFromDate(systemDateGet() - 30); rdpContract.parmToDate(systemDateGet()); rdpContract.parmIncludeContractors(true); // Set the RDP contract. controller.parmReportContract().parmRdpContract(rdpContract); // Construct and set a new SRSPrintDestinationSettings instance. srsPrintDestSettings = new SRSPrintDestinationSettings(); controller.parmReportContract().parmPrintSettings(srsPrintDestSettings); // Set the selected print destination to Docentric File print destination. srsPrintDestSettings.printMediumType(SRSPrintMediumType::File_DC); filePrintDestSettings = new DocPrintDestSettingsFile(); srsPrintDestSettings.parmFilePrintDestSettings_DC(filePrintDestSettings); // Set the Docentric File print destination settings. filePrintDestSettings.parmIsCalculatedFilename(true); // -- Folder of the output file. filePrintDestSettings.parmGeneratedDocFolderName(@'\\Shared'); // -- Name of the output file without the file extension. filePrintDestSettings.parmGeneratedDocFilenamePrefix('Birthdays'); // -- Output file format. filePrintDestSettings.parmOutputFileFormat(DocOutputFileFormat::DOCX); // -- Use the 'Next file name' to avoid overwriting the file if it already exists. filePrintDestSettings.parmUseNextFilename(true); // -- Don't save the output file to the underlying entity's Attachments. // (there is no underlying entity) filePrintDestSettings.parmSaveToAttachments(false); // -- Open the report after it is printed to a file. filePrintDestSettings.parmOpenGeneratedDoc(true); // Set the execution mode as needed. controller.parmExecutionMode(SysOperationExecutionMode::Synchronous); // Suppress the report dialog form. controller.parmShowDialog(false); // Execute the report. controller.startOperation(); } |
We have to set the target print destination to Docentric File print destination:
And we also have to fill the Docentric File print destination settings and relate them to the built-in SSRS print destination settings:
srsPrintDestSettings.parmFilePrintDestSettings_DC(filePrintDestSettings);
filePrintDestSettings.parmOutputFileFormat(DocOutputFileFormat::DOCX);
If you want to execute a Docentric Print Management SSRS report, e.g. Purchase Order from the code you can do it the standard way – as you would do with a built-in Print Management SSRS report.
1 2 3 4 5 6 7 8 9 10 11 |
static void runDocentricPrintMgmtSrsReportFromCode(Args _args) { MenuFunction reportMenuFunction; _args = new Args(); _args.record(VendPurchOrderJour::findByPurchId('000002')); reportMenuFunction = new MenuFunction( menuitemOutputStr(PurchPurchaseOrderOriginal), MenuItemType::Output); reportMenuFunction.run(_args); } |
The print destination settings of the report are already set with Print Management Form Setup.
The following job demonstrates, how you can print more than one existing purchase orders through code. The example below prints two purchase orders, which are used with Docentric AX, as files in Word output format.
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 |
static void runPurchPurchaseOrderFromCode(Args _args) { SRSPrintDestinationSettings srsPrintDestSettings; DocPrintDestSettingsFile filePrintDestSettings; PurchPurchOrderJournalPrint purchPurchOrderJournalPrint; Set purchOrderSet; purchOrderSet = new Set(Types::Record); // Add records to be printed. purchOrderSet.add(VendPurchOrderJour::findByPurchId('000002')); purchOrderSet.add(VendPurchOrderJour::findByPurchId('000003')); // Set print destination settings. srsPrintDestSettings = new SRSPrintDestinationSettings(); // Set the selected print destination to Docentric File print destination. srsPrintDestSettings.printMediumType(SRSPrintMediumType::File_DC); filePrintDestSettings = new DocPrintDestSettingsFile(); srsPrintDestSettings.parmFilePrintDestSettings_DC(filePrintDestSettings); // Set the Docentric File print destination settings. filePrintDestSettings.parmIsCalculatedFilename(true); // -- Folder of the output file. filePrintDestSettings.parmGeneratedDocFolderName(@'\\Shared'); // -- Name of the output file without the file extension. filePrintDestSettings.parmGeneratedDocFilenamePrefix('PurchOrder'); // -- Output file format. filePrintDestSettings.parmOutputFileFormat(DocOutputFileFormat::DOCX); // -- Use the 'Next file name' to avoid overwriting the file if it already exists. // -- NOTE: When printing more than one record we have to set this flag to True. filePrintDestSettings.parmUseNextFilename(true); // Initalize purchPurchOrderJournalPrint = PurchPurchOrderJournalPrint::construct(); purchPurchOrderJournalPrint.parmPrintFormletter(NoYes::Yes); purchPurchOrderJournalPrint.parmUsePrintManagement(false); purchPurchOrderJournalPrint.parmPrinterSettingsFormLetter(srsPrintDestSettings.pack()); // Print purchPurchOrderJournalPrint.printJournal(purchOrderSet); } |
See also
Walkthrough of Docentric HcmBirthday.Report >>
Download Resources of Docentric HcmBirthday.Report Example >>
How to Use a Print Management SSRS report as Docentric Report >>