Search Results for

    Show / Hide Table of Contents

    Email Customer Statement Job

    This page documents the customer statement email job implemented by codeunit 73053603 lts_opsaEmailCustStmt.

    Purpose

    The job sends customer statements by email with a PDF attachment generated from Report Selections for C.Statement.

    Object And Entry Points

    • AL object: codeunit 73053603 lts_opsaEmailCustStmt
    • Main runner: OnRun calls Process on lts_opsaEntry
    • Waiting entry creation: InsertWaitingEntry(CustomerNo, StatementReportParameters)
    • Email sender: EmailCustomerStatement(Customer, ToEmails, StatementReportParameters, WarningMessage)

    Prerequisites

    • App setting Enable Email Customer Statement Job is enabled.
    • At least one active Operations Automation Setup exists for:
      • Object Type to Run = Codeunit
      • Object ID to Run = lts_opsaEmailCustStmt
      • Blocked = false
    • Customer email address exists (resolved by lts_opsaEMail.GetCustomerEmailAddress).
    • Report Selections for C.Statement is configured.
    • If needed, a Custom Report Selection layout is configured for the customer.

    How Waiting Entries Are Created

    InsertWaitingEntry(CustomerNo, StatementReportParameters) performs the following:

    1. Reads the customer record.
    2. Resolves report selection for C.Statement.
    3. Updates report parameters to include the target customer dataitem and resolved date values.
    4. Finds matching setup records for this codeunit.
    5. Prevents duplicate waiting entries for the same setup and source record unless AllowReEntry(true) is used.
    6. Creates a new entry with:
      • Description: To email statement: {Customer No.}
      • Source document type: Customer
      • Status: Waiting
    7. Stores statement XML parameters in the entry record table filter value field.

    Statement Parameter Handling

    The job supports both explicit dates and formulas.

    • Extracts options from XML Field nodes.
    • Supports StartDateFormula and EndDateFormula relative to WorkDate.
    • If options are empty, falls back to:
      • StartDate = 1900-01-01 (or customer date filter minimum)
      • EndDate = WorkDate (or customer date filter maximum)
    • Ensures StartDate is not later than EndDate.

    Processing Flow

    When the entry runs:

    1. Process resolves Source Record ID to Customer.
    2. Reads saved XML parameters from the entry.
    3. EmailCustomerStatement builds email details:
      • Subject: Customer {Customer No.}: Please find your customer statement
      • Body: HTML generated from selected report and layout; falls back to subject text.
      • Attachment: PDF rendered from selected statement report and saved XML parameters.
      • Filename: {CustomerNo}_statement.pdf
    4. Email is sent through lts_opsaEMail.SendEmail.
    5. A success or warning log is created.

    Warning Path

    If statement PDF generation returns no content, the code uses a TryFunction path:

    • Warns instead of failing hard.
    • Writes warning message from last error text, or fallback text:
      • Nothing to generate for customer {Customer No.}

    Logging

    • Success log status: Success
    • Success log format: Customer statement emailed: {email list}
    • Warning log status: Warning
    • Warning message: generated from report attachment generation failure.

    Common Failure Points

    • To email address is blank for the customer.
    • Report selection for C.Statement is not configured.
    • Invalid or empty statement parameter XML.
    • Date formula evaluation issues in provided parameters.
    • Email scenario or sending account is not configured in Business Central.

    Related Pages

    • How-to
    • Troubleshooting
    • Concepts
    • Edit this page
    In this article
    Back to top Lonicera