This step-by-step tutorial outlines how to create a document and attach it to an email using the DocumentsCorePack custom connector for PowerAutomate (Microsoft Flow).
Overview of the Flow
This flow is triggered on the update of a record (Account in our case), it then creates an Email using the “Create new Record” step from the common data services connector. Afterwards we are using our DocumentsCorePack custom connector to create an email body from a DCP Template and attach it to the email. Then we create an email attachment and attach it to the same email. The last step finally sends the email.
When you create a new flow, you have to decide which action will trigger the flow. In our case we have simply added a trigger on the update of the Account.
2. Create Email
In the second step we create an Email Message, you can leave the sender, recipient and regarding empty for now, as our DocumentsCorePack custom connector offers a very easy way to fill them later. You can still already fill the Subject and Description to your liking.
3. Create Email Body
To create the Email Body, we are using the DocumentsCorePack custom connector and choose the step “Create Document Job (sync)”. In this step it is mandatory to specify a template which shall be used to create the email body, and an Entity ID with which the Template shall be merged. (NOTE: The template needs to be created for the Entity Type specified in the Email ID) To create the Email Body we must choose the Filetype “HTML”.
4. Attach Email Body
After creating the Email Body, we need to attach it to the Email. For this we select the Document that was created in the previous Create Email Body step, this can be found under “Document (Base 64 Encoded)”. We also take the Filename from the previous step and the Email Message from the Create Email step.
Here you can see what the “Document (Base 64 Encoded)” looks like:
5. Create Attachment
In this step we want to create an additional attachment that shall be attached to the final email.
Again, we have to choose a Template, an Entity ID and an output FileType. As we want an attachment this time we are choosing “PDF”:
6. Attach Email Attachment
Again, we have to attach the created document to the email. This time we select the “Document (Base 64 Encoded)” and the Filename from the Create Attachment Step. Additionally, we also need to fill Email ID with the “Email Message” from the “Create Email “Step.
7. Send Email
Now that the Email Body and Email Attachment are attached to our Email, we want to finally send the email. For the “Email To Send” we choose the “Email Message” from the Create Email step.
Based on the trigger you have chosen you can either use the “Owner” or “Modified By” user to get the current user, if you have a trigger that allows it you can also get the current user using the “User ID” from the dynamic values. This user can be specified as the sender of the email. For Sender (Schema name) we choose the Entity Type “User”.
Now we also have an option to specify the “Regarding” of the Email, for this we used the Regarding (Id) “Account” and the Regarding (Schema Name) Entity Type “Account”.
For the To-Recipient we have chosen the To-ID “Primary Contact” and the To-Schema name Entity Type “Contact”.
In Short: It is important that the “Schema name” points to the Entity Type of the ID that is specified.