How to Run a Docentric Basic Report in Batch
We can run a Docentric Basic report in batch through the report dialog form for every print destination except for Screen and Generate DS.
By clicking the OK button on the batch dialog form, the batch job is created and added to the batch queue.
Running a report in batch from the code
We can also run a Docentric Basic report in batch from the code.
Let’s say that we want to schedule a job for sending particular documents (e.g. Collection letter notes) to the corresponding vendors, i.e. to a vendor contact email, on the end of each month. We can write the business logic that iterates through the all required records and for the each record creates a batch job that runs a particular report to the email of the corresponding vendor.
The example below is showing how to print purchase orders, selected by certain conditions, as reports to the emails of the corresponding vendors in batch.
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 |
public static void runBasicReportFromCodeInBatch(Args _args) { DocPrintReportBase docPrintReport; DocReportBatch docReportBatch; DocPrintReportSettings printReportSettings; DocPrintDestSettings printDestSettings; DocPrintDestSettingsEmail emailPrintDestSettings; PurchTable selectedPurchTable; str reportCaption; // Select particular purchase orders according to certain conditions... while select selectedPurchTable where selectedPurchTable.PurchId == '000002' || selectedPurchTable.PurchId == '000003' { // Create the report caption. reportCaption = strFmt('Purchase order %1', selectedPurchTable.PurchId); // Instance the Print Report Manager (PRM) class for the report. docPrintReport = DocPrintReportBase::construct(classStr(DocPrintPurchOrderPrintReport), reportCaption); // Set the Report Execution Table context. docPrintReport.setReportExecutionContextRecord(selectedPurchTable); // Suppress the report dialog form. docPrintReport.showDialog(false); // Set values of the report parameters. docPrintReport.setParameterValue('PurchId', selectedPurchTable.PurchId); docPrintReport.setParameterValue('IncludeSalesTax', true); // Prepare the print report settings. printReportSettings = docPrintReport.printReportSettings(); printDestSettings = docPrintReport.printDestSettings(); printReportSettings.parmSaveToArchive(false); printReportSettings.parmPrintDestination(DocPrintDestination::Email); // NOTE: We are using the default report template, so we are not setting the template // via printReportSettings.parmTemplateId(). // Prepare the Email print destination settings. emailPrintDestSettings = new DocPrintDestSettingsEmail(); printDestSettings.parmEmailPrintDestSettings(emailPrintDestSettings); emailPrintDestSettings.parmEmailTo(selectedPurchTable.vendorEmail()); emailPrintDestSettings.parmEmailSubject(reportCaption); emailPrintDestSettings.parmEmailAttachmentFileFormat(DocOutputFileFormat::PDF); // Add one additional attachment that is not a report. emailPrintDestSettings.addAdditionalAttachment(@'C:\Temp\NDA.docx'); // Execute the report in batch. docReportBatch = DocReportBatch::constructFromDocPrintReportBase(docPrintReport, false); // TODO: Set the batch job recurrence. docReportBatch.batchInfo().parmBatchExecute(true); docReportBatch.batchInfo().doBatch(true); } info('All required purchase orders are successfully scheduled to be sent to vendor emails.'); } |
See also
How to Run a Docentric Basic Report from Code >>
How to Send a Docentric Basic Report to Multiple Print Destinations >>
Basic Report Examples >>