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:
- Reads the customer record.
- Resolves report selection for C.Statement.
- Updates report parameters to include the target customer dataitem and resolved date values.
- Finds matching setup records for this codeunit.
- Prevents duplicate waiting entries for the same setup and source record unless AllowReEntry(true) is used.
- Creates a new entry with:
- Description: To email statement: {Customer No.}
- Source document type: Customer
- Status: Waiting
- 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:
- Process resolves Source Record ID to Customer.
- Reads saved XML parameters from the entry.
- 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
- Email is sent through lts_opsaEMail.SendEmail.
- 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.