Power Automate: Create an Excel file during runtime and send it as email attachment through MS Flows

I was working on a requirement where Dataverse entity record needs to be export in excel and send as an email attachment.

In this scenario, each record must have a separate excel file, and as we know there is no way to create an excel file dynamically through flow.

To achieve the above task, I have followed below steps:

Step 1: 

I created an excel template in one drive and this template has one table and two columns i.e. Name and City:

We can increase/decrease columns as per requirement.




In this example, my template name is "Sample sheet.xlsx"

Step 2:

Create a Microsoft flow that triggers on the creation of "Contact" in Dataverse:


Then add a new step to get the file template from one drive that was created in Step 1:


Next, Add a new step to copy the template with a new name at a new location on onedrive:

I have created a new folder with the name "Copies" in onedrive before creating the above step.

The next step is to compose rows, In step 1, I have created two columns in the template and here I am assigning value in those two columns:


Now, next step is to add row in excel, This is a very important step.



In file column, I have written below expression:

split(outputs('Copy_template_in_new_location')?['body/Id'],'.')[1]
In this expression, I set id of step "Copy template in new location".

In Row, Set output of step "Compose rows".

The next step is for delay 5 seconds:



Next, Get updated file content:

Finally, send email and set file content as an attachment:



Save the flow and test it.

The final layout of the flow will look like this:


Please subscribe blog for regular updates.

Cheers,
Rocker

























Comments

  1. The best Article that I have never seen before with useful content and very informative.Thanks for sharing info. Dynamics 365 Marketing Functional Consultant Associate

    ReplyDelete

Post a Comment

Popular posts from this blog

Power Automate: Create and attach Dataverse note or activity with an entity record through MS flow

{Error:Fetch XML}: The date/time format is not valid, or the value is outside the supported range

How to set privilege for Activity Attachment (activitymimeattachment) in Dynamics 365 or PowerApps