Document Approval - Sent and Approval Type is Letter of Engagement
Flow Overview
- Name: Document Approval - Sent and Approval Type is Letter of Engagement
- Purpose: Sends a templated email with populated content when a Document Approval of type "Letter of Engagement" is sent.
- Date Created / Last Modified: [Insert date here]
Dependencies
- Dataverse
- Document Approvals
- Contacts
- Email Messages
- Email Contents
- PowerApps
- Manual trigger
- TTS Consulting Utility
- ReplaceWildcardsInText
Trigger
- Type: Manual
- Source: PowerApps
- Input Parameter:
Document Approval ID
Flow Details
Get Records from Input Parameters
-
Get Document Approval by ID
Table name: Document Approvals
Row ID: PowerApps input (Document Approval ID) -
Get Contact by ID
Table name: Contacts
Row ID: PowerApps input (Contact ID from Document Approval)
Initialize Variables
Name: DocumentApprovalURL
Type: String
Value:
concat(baseurl, '/main.aspx?etn=tt_documentapproval&id=', DocumentApprovalID, '&pagetype=entityrecord')
Name: EmailRecipientsArray
Type: Array
Value: []
Name: EmailRegardingContact
Type: String
Value: (empty)
Add Recipients
If Manager is Populated
Manager (Value) is not equal to null
- Append to
EmailRecipientsArray
:
{
"participationtypemask": 3,
"partyid@odata.bind": "/systemusers({Manager ID})"
}
List Reception Contact
FetchXML Query:
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
<entity name="contact">
<attribute name="fullname" />
<attribute name="emailaddress1" />
<attribute name="tt_clientcode" />
<attribute name="tt_managername" />
<attribute name="ownerid" />
<attribute name="contactid" />
<order attribute="fullname" descending="false" />
<filter type="and">
<condition attribute="contactid" operator="eq" uitype="contact" value="{Service Contact}" />
</filter>
</entity>
</fetch>
Condition:
length(body('List_Reception_Contact')?['value']) is equal to int(1)
- Append to
EmailRecipientsArray
:
{
"participationtypemask": 3,
"partyid@odata.bind": "/contacts({Service Contact ID})"
}
Append Sender & BCC to EmailRecipientsArray
- FlowEmailSender:
{
"participationtypemask": 1,
"partyid@odata.bind": "/systemusers({FlowEmailSender ID})"
}
- FlowEmailBCC:
{
"participationtypemask": 4,
"partyid@odata.bind": "/contacts({FlowEmailBCC Contact ID})"
}
Set Email Regarding Contact
Name: EmailRegardingContact
Type: String
Value: /contacts({Contact ID})
Email Template and Dynamic Replacement
Get Email Content Template
Inputs:
{
"FlowName": "Document Approval - Sent and Approval Type is Letter of Engagement",
"FlowEmailID": "1"
}
FetchXML for Email Contents:
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
<entity name="tt_emailcontent">
<attribute name="tt_emailcontentid" />
<order attribute="tt_emailsubject" descending="false" />
<filter type="and">
<condition attribute="tt_flowname" operator="eq" value="{FlowName}" />
<condition attribute="tt_flowemailid" operator="eq" value="{FlowEmailID}" />
</filter>
</entity>
</fetch>
Update EmailTemplate
ReplacementMapping JSON:
[
{
"Wildcard": "{{contact.tt_clientcode}}",
"Replacement": "@{outputs('Get_Contact_by_ID')?['body/tt_clientcode']}"
},
{
"Wildcard": "{{contact.fullname}}",
"Replacement": "@{outputs('Get_Contact_by_ID')?['body/fullname']}"
},
{
"Wildcard": "{{var.documentapprovalurl}}",
"Replacement": "@{variables('DocumentApprovalURL')}"
}
]
Replace Wildcards
- EmailSubject Replacement:
{
"text": "@{outputs('Get_EmailContents_by_ID')?['body/tt_emailsubject']}",
"ReplacementMapping": "@{outputs('Update_EmailTemplate')}"
}
- EmailBody Replacement:
{
"text": "@{outputs('Get_EmailContents_by_ID')?['body/tt_emailbody']}",
"ReplacementMapping": "@{outputs('Update_EmailTemplate')}"
}
Compose Email
Compose EmailSubject: Output from subject wildcard replacement
Compose EmailBody: Output from body wildcard replacement
Send Email
- Add a new Email Messages row
Table: Email Messages
Activity Parties: EmailRecipientsArray
- Perform SendEmail bound action
Table: Email Messages
Action Name: SendEmail
Row ID: Email Message ID
IssueSend: Yes
Final Response
- Respond to PowerApp or Flow
{
"Success": "Success"
}
Summary
This flow is triggered when a Document Approval of type Letter of Engagement is sent:
- It pulls data from Dataverse and Contact records.
- It builds a dynamic recipient list including Manager, Reception, Sender, and BCC.
- It dynamically generates a customized email using a central email template and TTS’s ReplaceWildcardsInText utility.
- The composed email is saved and sent, and the result is returned to PowerApps.