🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
SysDocBatch
This page was created by Hans.karlsen on 2024-06-04. Last edited by Wikiadmin on 2026-07-29.

You can use SysDocBatch to collect report and other generated documents into one user-controlled batch, then convert, zip, and download that batch from a ViewModel in Turnkey and WPF-Wecpof.

What SysDocBatch does

SysDocBatch is a built-in MDriven system-document pattern: Sys means system and Doc means document. It changes the usual report-generation flow from an immediate download to a collected batch.

Normally, generating a report downloads its output directly, for example as an .odt or .ods file. When an active SysDocBatch is available through SysSingleton.oclSingleton.CurrentSysDocBatch, generated output is added as a SysDoc to that batch instead. The user or developer can then decide when to convert, zip, or download the collected files.

This pattern is intended for cases such as generating one report per selected customer and delivering all reports in one ZIP file, rather than triggering a separate download for every customer.

Element Purpose
SysDocBatch Holds a collection of documents through its SysDocs association.
SysDoc Represents one document in the batch, including its binary data, name, optional ZIP directory, and conversion results.
SysDocBatchView A ViewModel rooted in SysDocBatch. It is shown as a modal window when the first SysDoc is added to a batch.
SysSingleton.oclSingleton.CurrentSysDocBatch The current batch reference. When it is set, generated documents are collected rather than downloaded immediately.

Keep SysDocBatch and SysDoc transient in your model. They represent documents being prepared for the current workflow, not business data that must be stored permanently.

How collection works

  1. Create or obtain one SysDocBatch for the current workflow.
  2. Set SysSingleton.oclSingleton.CurrentSysDocBatch to that batch.
  3. Generate one or more reports or documents.
  4. For each generated output, MDriven adds a SysDoc to CurrentSysDocBatch.SysDocs instead of initiating an immediate download.
  5. When the first SysDoc is added, the SysDocBatchView ViewModel opens as a modal window.
  6. In SysDocBatchView, let the user convert files when needed, create a ZIP archive, and download the resulting file.

For example, an action that generates monthly statements for five customers creates five SysDoc objects attached to the same SysDocBatch. The user sees one modal batch window and can download all five statements together.

SysDoc data

Member Meaning
DocData: Blob The document data used for conversion and download.
DocName: String The file name, including its extension. For example, Statement-2026-07.odt.
DocDirectory: String The folder name to use for the file when organizing files inside a ZIP archive.
ConversionLog: Text The message log returned by LibreOffice during conversion.
InfoOnFailed: String The exception message when conversion fails.

A document uploaded for independent conversion must have both its document data and a DocName with the full file name and extension. The extension identifies the source format used by the conversion workflow.

Convert documents with LibreOffice

SysDocBatch uses LibreOffice for supported document conversions. LibreOffice is a separate product with its own license and must be installed on the server running Turnkey.

Before enabling conversion:

  1. Install LibreOffice on the Turnkey server.
  2. Set SysMDrivenMiscSettingsSingleton.oclSingleton.LibreOfficeInstallPathAndExe to the LibreOffice executable path. A typical value is C:\Program Files\LibreOffice\program\soffice.exe.
  3. Configure LibreOffice for server use as described in HowTos:Use LibreOffice for PDF Conversion. In particular, disable online updates and Java support to avoid server-update issues and reduce per-document load time.

The SysDoc conversion operations are:

Operation Documented result
ConvertToPDFWithLibreOffice Converts an .odt document to .pdf.
ConvertToMSOfficeWithLibreOffice Converts OpenDocument spreadsheet or text output to Microsoft Office formats as supported by the configured conversion workflow.

After a conversion, inspect ConversionLog and InfoOnFailed when a document does not produce the expected output. Do not assume that a conversion succeeded only because the action was started.

Add the pattern to an existing document workflow

Use this approach when your application already generates reports and you want to collect those outputs before delivery.

  1. In TK Live View, merge the SysDocBatch pattern into your model. The pattern is available from the MDriven components repository maintained by supportMDriven/MDrivenComponents.
  2. Configure LibreOffice on the Turnkey server and set SysMDrivenMiscSettingsSingleton.oclSingleton.LibreOfficeInstallPathAndExe.
  3. Create the template ViewModel that generates your text documents.
  4. Create a class action on that ViewModel to generate the documents.
  5. In the action workflow, create a SysDocBatch the first time it is needed and use that same batch for subsequent generated documents.
  6. Ensure that the current batch is assigned to SysSingleton.oclSingleton.CurrentSysDocBatch before report generation. Generated reports are then attached to the batch instead of downloaded immediately.
  7. Navigate to SysDocBatchView to present the collected documents and offer conversion or delivery actions.

For a batch containing multiple reports, attach every SysDoc to the same SysDocBatch. Creating a new batch for every report defeats the purpose of controlled batch delivery.

Use SysDocBatch as an independent converter

Use this approach when users need to upload existing documents and convert them rather than generate reports from a template.

  1. Merge the SysDocBatch pattern from TK Live View.
  2. Install and configure LibreOffice on the Turnkey server. Set SysMDrivenMiscSettingsSingleton.oclSingleton.LibreOfficeInstallPathAndExe.
  3. Create autoforms for the pattern classes.
  4. In the SysDoc view, upload each source document.
  5. Set DocName to the complete file name, including its extension. For example, Agenda.odt.
  6. Add the uploaded SysDoc objects to a SysDocBatch.
  7. Open SysDocBatchView.
  8. Use the PDF action to convert eligible documents to PDF.
  9. Create a ZIP archive when you want to download several documents together, then download the ZIP.

Zip and download a batch

The ViewModel self operators can create ZIP data and start a download. For example:

vData:=selfVM.SysDocBatchZip( self )
selfVM.Download( 'Somefile.zip' , vData )

In this example, self is the SysDocBatch, vData receives the ZIP data, and Download sends that data to the user as Somefile.zip. Use a file name that reflects the content of the batch, such as CustomerStatements.zip.

For the operator entry, see Documentation:OCLOperators SysDocBatchZip.

Operational notes

  • SysDocBatch is recognized by TurnkeyServer and WPF-Wecpof. MDrivenServer performs the ZIP and conversion work described by this pattern.
  • A batch window opens on the first added SysDoc. Design your workflow so that all documents intended for one delivery are attached to that same batch.
  • Conversion depends on the configured LibreOffice installation on the server. If the executable path is missing or conversion fails, use the SysDoc conversion log and failure information to diagnose the result.
  • SysDocBatch is for application documents such as reports. For model documentation output in XPS format, use Documentation:Documtr and XPS.

See also