How to Send a Docentric Basic Report to Multiple Print Destinations
Let’s say that we need to print a currently selected purchase order from the Purchase Orders list page as a report to a DOCX output file to a shared location, e.g. \\share\ on a button click. At the same time, we want to email this report in the PDF output format to the vendor and also to save the report to Print Archive.
Assume that we already developed a Basic report that print a purchase order, including the report template as well. Thus we have the DocPrintPurchOrderPrintReport class as the report Print Report Manager (PRM) class, which defines the report parameters and the Report Menu Item pointing to this class.
Our PRM class contains so far the addParameters() method and the default implementation of the main() method.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
public void addParameters() { DocReportParameter docReportParameter; // PurchId. docReportParameter = DocReportParameter::constructFromEdt(extendedTypeStr(PurchId)); docReportParameter.parmIsHidden(true); this.addParameter(docReportParameter); // IncludeSalesTax. docReportParameter = DocReportParameter::constructFromEnum(enumStr(boolean), 'IncludeSalesTax'); // NOTE: In real case scenarios please use label IDs instead of literal strings. docReportParameter.parmLabelId('Include sales tax'); this.addParameter(docReportParameter); } |
Now, use the Report Menu Item with a MenuItemButton form control on the Action Pane of the Purchase Orders list page and label it as Print PO to Multiple Destinations. This menu item button inherits Data Source from the list page Action Pane, which is the PurchaseTable form data source. When the Print PO to Multiple Destinations button is clicked, the main() method of the report PRM class is invoked. If we leave the default implementation of the main() method as it is, the report dialog form will be shown. In order to suppress the report dialog as well as to send the report to the multiple print destinations as required, we have to change the implementation of the main() method.
Below is the customized main() method of the report PRM class.
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 62 63 64 65 66 67 68 69 70 71 72 |
public static void main(Args _args) { DocPrintReportBase docPrintReport; PurchTable callingPurchTable; str reportCaption; DocPrintReportSettings printReportSettings; DocPrintDestSettings printDestSettings; DocPrintDestSettingsFile filePrintDestSettings; DocPrintDestSettingsEmail emailPrintDestSettings; // Get the report caption. reportCaption = DocLabelHelper::getLabelForMenuItem(_args.menuItemName(), _args.menuItemType()); // Instance the PRM class for the report. docPrintReport = DocPrintReportBase::construct(classStr(DocPrintPurchOrderPrintReport), reportCaption, _args.record()); // Suppress the report dialog form. docPrintReport.showDialog(false); // Set the parameter value for the hidden parameter PurchId. callingPurchTable = docPrintReport.getReportExecutionContextRecord(); if (!callingPurchTable) { throw error('Invalid report execution context. Data source of the report menu item should be set to PurchTable.'); } docPrintReport.setParameterValue('PurchId', callingPurchTable.PurchId); // Set the parameter value for the IncludeSalesTax parameter. docPrintReport.setParameterValue('IncludeSalesTax', true); // Prepare the print report settings. printReportSettings = docPrintReport.printReportSettings(); printDestSettings = docPrintReport.printDestSettings(); printDestSettings.setDefaultParmValuesAllDestinations( printReportSettings.parmReportId(), printReportSettings.parmReportCaption()); printReportSettings.parmSaveToArchive(false); // NOTE: We can select a different template for each print destination, if needed. // Now the default report template is being used. // Prepare the Email print destination settings. emailPrintDestSettings = new DocPrintDestSettingsEmail(); printDestSettings.parmEmailPrintDestSettings(emailPrintDestSettings); emailPrintDestSettings.parmEmailTo(callingPurchTable.vendorEmail()); emailPrintDestSettings.parmEmailSubject( strFmt('Purchase order %1', callingPurchTable.PurchId)); emailPrintDestSettings.parmEmailAttachmentFileFormat(DocOutputFileFormat::PDF); // Prepare the File print destination settings. filePrintDestSettings = new DocPrintDestSettingsFile(); printDestSettings.parmFilePrintDestSettings(filePrintDestSettings); filePrintDestSettings.parmIsCalculatedFilename(true); filePrintDestSettings.parmGeneratedDocFolderName(@'\\share'); filePrintDestSettings.parmGeneratedDocFilenamePrefix( strFmt('PurchOrder_%1_%2', callingPurchTable.OrderAccount, callingPurchTable.PurchId)); filePrintDestSettings.parmOutputFileFormat(DocOutputFileFormat::DOCX); // Execute the report. // -- Print the report to the File print destination. printReportSettings.parmPrintDestination(DocPrintDestination::File); docPrintReport.run(); // -- Print the report to the Email print destination. printReportSettings.parmPrintDestination(DocPrintDestination::Email); docPrintReport.run(); // -- Print the report to the Print Archive print destination. printReportSettings.parmPrintDestination(DocPrintDestination::Archive); docPrintReport.run(); } |
See also
Download the Similar Example >>
How to Run a Docentric Basic Report from Code >>
How to Suppress a Success Message after Report Execution >>