Email Invoice Job
This page documents the posted sales invoice email job implemented by codeunit 73053601 lts_opsaEmailInvoice.
Purpose
The job sends posted sales invoices to customers by email with a PDF attachment generated from Report Selections for S.Invoice.
Object And Entry Points
- AL object: codeunit 73053601 lts_opsaEmailInvoice
- Main runner: OnRun calls Process on lts_opsaEntry
- Waiting entry creation: InsertWaitingEntry(InvoiceNo)
- Email sender: EmailInvoice(SalesInvoice, ToEmails)
Prerequisites
- App setting Enable Email Invoice Job is enabled.
- At least one active Operations Automation Setup exists for:
- Object Type to Run = Codeunit
- Object ID to Run = lts_opsaEmailInvoice
- Blocked = false
- Customer email address exists (resolved by lts_opsaEMail.GetCustomerEmailAddress).
- Report Selections for S.Invoice is configured.
- If needed, a Custom Report Selection layout is configured for the customer.
How Waiting Entries Are Created
InsertWaitingEntry(InvoiceNo) performs the following:
- Reads the posted sales invoice record.
- Verifies the feature flag Enable Email Invoice Job.
- Finds matching setup records for this codeunit.
- Applies setup record filters through GetRecordTableFilterValue and Sales Invoice Header No.
- Prevents duplicate waiting entries for the same setup and source record unless AllowReEntry(true) is used.
- Creates a new entry with:
- Description: To email invoice: {Invoice No.}
- Source document type: Sales Invoice
- Status: Waiting
Processing Flow
When the entry runs:
- Process resolves Source Record ID to Sales Invoice Header.
- EmailInvoice builds email details:
- Subject: Customer {Bill-to Customer No.}: Please find your invoice {Invoice No.}
- Body: HTML generated from selected report and layout; falls back to subject text.
- Attachment: PDF rendered from selected invoice report.
- Filename: {InvoiceNo}_invoice.pdf
- Email is sent through lts_opsaEMail.SendEmail.
- A success log is created: Invoice emailed: {ToEmails}.
Filtering Behavior
Setup-level record filters are evaluated against Sales Invoice Header and invoice No. Only invoices included by setup filters generate waiting entries.
Logging
- Success log status: Success
- Log message format: Invoice emailed: {email list}
Common Failure Points
- To email address is blank for the bill-to customer.
- Report selection for S.Invoice is not configured.
- Custom report layout configuration is invalid.
- Email scenario or sending account is not configured in Business Central.