One of the nice features available out of the box is the ability to generate Word Templates in an easy way while using customer engagement apps (Dynamics 365 Sales, Dynamics 365 Customer Service, Dynamics 365 Field Service, Dynamics 365 Marketing, and Dynamics 365 Project Service Automation).
For the purpose of this article we will be using the Invoice out of the box Template and using it to send out email with the generated word template.
Please follow the below steps to get this working:
- Create a new solution.
- Create a new Process , Set Process Name to Action: Set Work Template, Set Category to Action and Entity to Invoice and click ok
3. Click on Add Step -> Perform Action
4. Choose the Action SetWordTemplate
5. Click on Properties, Choose the Selected Template and the Target and click Save and close
6. Click on Activate and Activate your Business Process
7. To call the action from your power automate , Choose Perform a bound action on the CDS Current Environment Current
Choose the Table to be Invoices and Select the Action Name as below and pass the Invoice ID
8. To get the generated document as mentioned above this has created a note against the invoice record so in order to get the generated note record against the invoice.
Add a List Rows Action with the below FetchXML:
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false"> <entity name="annotation"> <attribute name="subject" /> <attribute name="notetext" /> <attribute name="filename" /> <attribute name="annotationid" /> <order attribute="createdon" descending="false" /> <filter type="and"> <condition attribute="isdocument" operator="eq" value="1" /> <condition attribute="filename" operator="eq" value="Invoice.docx"/> </filter> <link-entity name="invoice" from="invoiceid" to="objectid" link-type="inner" alias="ab"> <filter type="and"> <condition attribute="invoiceid" operator="equitype="invoice" value="Invoice ID" /> </filter> </link-entity> </entity> </fetch>
You will need to Replace the below part in the above fetch with your regarding entity for the note which in my example is invoice, in other scenarios it can be contact or account.
<link-entity name="invoice" from="invoiceid" to="objectid" link-type="inner" alias="ab"> <filter type="and"> <condition attribute="invoiceid" operator="equitype="invoice" value="Invoice ID" /> </filter> </link-entity>
Also replace the below filter condition with the template name .docx
<condition attribute="filename" operator="eq" value="Invoice.docx" />
9. This is sorted desc by created on , so getting the first record on the list gets the last generated document.
10. Next we need to get the GUID first record from List Rows, so use a compose data operation with the below expression:
11. Use the Get a row by Id and pass the outputs from the compose data operation to the ROW ID
12. Add a new send email step, Pass the file name and the Document properties from the Get a row by ID in step 11 , For the document to be displayed correctly in the email you need to use the expression below for the Attachment Content and not directly pass the document.