Hi everyone,
I'm working on D365 Finance & Operations and trying to build fully dynamic HTML email templates that get sent automatically when a Purchase Order (PO) or Purchase Requisition (PR) is submitted to workflow.
**Current Setup:**
- Workflow types: Purchase Order approval + Purchase Requisition approval
- Email template: HTML-based, stored in System Email Templates
- Email is triggered automatically on workflow submission (no custom X++)
- SMTP configured and working fine
**What I Want to Achieve:**
I want the email body to be dynamic — meaning it should include runtime data at the time of submission.
For **Purchase Order (PurchTable / PurchLine)**:
- PO number, vendor name, order date, delivery address, currency
- PO Lines: item number, description, quantity, unit price, net amount (repeating section)
- Total amount including VAT
- Assigned approver name
For **Purchase Requisition (PurchReqTable / PurchReqLine)**:
- PR number, requester name, request date, department
- PR Lines: item number, description, quantity, unit price, net amount (repeating section)
- Total amount
- Assigned approver name
**What I've Tried:**
I'm aware of the standard `%token%` placeholder system in System Email Templates, but it has two limitations:
1. The available tokens are predefined and limited
2. It does not support loops/repeating sections (e.g. rendering multiple PO/PR Lines dynamically)
**What I've Explored:**
I looked into using `SysEmailDistributor` as a CoC extension point to intercept the email body before it's sent and replace custom placeholders like `%POLines%` or `%PRLines%` with dynamically built HTML rows from X++.
The class has these methods that seem relevant:
- `processEmails`
- `getEmail`
- `splitEmail`
- `substituteImageURLs`
**My Questions:**
1. Is `SysEmailDistributor` the right class to extend via CoC for intercepting and modifying workflow email bodies before sending?
2. Which specific method is the correct interception point for modifying the HTML body?
3. How can I identify which document (PO or PR) triggered the email so I can query the correct table?
4. Is there a cleaner/supported approach to pass runtime variables — especially repeating line data — into a workflow email template?
5. Has anyone successfully implemented a fully dynamic HTML email body for both PO and PR workflow notifications in D365 F&O?
Any guidance, code snippets, or architectural suggestions would be highly appreciated.
Thanks!