web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

D365 F&O — Dynamic HTML Email Templates with Runtime Variables for PO & PR Workflow Notifications

(0) ShareShare
ReportReport
Posted on by 18
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!
Categories:
I have the same question (0)
  • André Arnaud de Calavon Profile Picture
    303,950 Super User 2026 Season 1 on at
    Moved the question from the Dynamics 365 General to the Dynamics 365 Finance forum.
     
  • Suggested answer
    André Arnaud de Calavon Profile Picture
    303,950 Super User 2026 Season 1 on at
    Hi Raed,
     
    The SysEmailDistributor class is not the correct place as this is sending emails that are put in a queue table by different features. You can check if you can extend the class EventNotificationWorkflow class instead.

    You can also consider creating a Power Automate flow triggered from workflow events that will compile the required data and will send the email to the users.
  • Raed Bzour Profile Picture
    18 on at
    Hi Andre,

    Thanks a lot for the quick response, really appreciated!

    Unfortunately Power Automate is off the table for us — management decision — so we need to keep everything inside D365 F&O using X++.

    I had a look at EventNotificationWorkflow after your suggestion and stumbled upon createEmailParameterXml, which seems like the right place to hook into before the email goes out. My thinking is to extend it via CoC, build the dynamic HTML for the repeating sections (PO/PR lines) in X++, and inject them as custom tokens like %PurchLines% into the XML so the template can pick them up.

    Does that sound like a valid approach? Also, is parmRefRecId the right way to get back to the source document (PurchTable or PurchReqTable) from inside the extension?

    Any confirmation or pointers would go a long way!

    Thanks again!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 692

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 454 Super User 2026 Season 1

#3
Syed Haris Shah Profile Picture

Syed Haris Shah 311 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans