How to Suppress a Success Message after Report Execution
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. After the report is saved to the file location, it needs to be opened and the Infolog with the message about successful report execution needs to be suppressed.
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 File. 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 File 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 suppress the success message about report execution and to fulfill the rest of the above written report requirements, 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 73 74 |
public static void main(Args _args) { DocPrintReportBase docPrintReport; PurchTable callingPurchTable; str reportCaption; DocPrintReportSettings printReportSettings; DocPrintDestSettings printDestSettings; DocPrintDestSettingsFile filePrintDestSettings; // Get the report caption. reportCaption = DocLabelHelper::getLabelForMenuItem(_args.menuItemName(), _args.menuItemType()); // Instance the Print Report Manager (PRM) class for the report. docPrintReport = DocPrintReportBase::construct(classStr(DocPrintPurchOrderPrintReport), reportCaption, _args.record()); // Suppress the report dialog form. docPrintReport.showDialog(false); // Suppress the report success message. docPrintReport.suppressSuccessPrintReportMsg(true); // 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 and destination settings. printReportSettings = docPrintReport.printReportSettings(); printDestSettings = docPrintReport.printDestSettings(); // Set the target print destination to File. printReportSettings.parmPrintDestination(DocPrintDestination::File); // Don't save the report to Print Archive. printReportSettings.parmSaveToArchive(false); // NOTE: We can select a different than the default template, if needed. filePrintDestSettings = new DocPrintDestSettingsFile(); printDestSettings.parmFilePrintDestSettings(filePrintDestSettings); // Set the flag that enables to specify output folder and file name separately. filePrintDestSettings.parmIsCalculatedFilename(true); // Set the output folder. filePrintDestSettings.parmGeneratedDocFolderName(@'\\share'); // Set the output file name (without extension). filePrintDestSettings.parmGeneratedDocFilenamePrefix(strFmt('PurchOrder_%1', callingPurchTable.PurchId)); // Set the output format. filePrintDestSettings.parmOutputFileFormat(DocOutputFileFormat::DOCX); // If on the output location already exists the file with the same name as // the specified report output file name, prevent the existing file to be overridden. filePrintDestSettings.parmUseNextFilename(true); // Don't save the report to the selected PurchTable record's Attachments. filePrintDestSettings.parmSaveToAttachments(false); // Open the report after the report is printed to the specified file location. filePrintDestSettings.parmOpenGeneratedDoc(true); // Execute the report. docPrintReport.run(); } |
See also
Download the Similar Example >>
How to Run a Docentric Basic Report from Code >>
How to Send a Docentric Basic Report to Multiple Print Destinations >>