# Power Automate: Add a table in Email

Hi guys, \
Last week, my client approached me with a request: **they wanted the system to be capable of sending email notifications to the sales manager, containing a list of new Deals daily.** (It means the list of Deals has "New" status)

...and I said, "Yes, sure".  -> Now, we will do that.

## My propose: Using Power Automate

The details of my Power Automate:

* Type of Power Automate: **Scheduled.**
* Frequency: **Daily** at 00:05 am
* The flow will filter all **Deal records** that have the **status reason** "**New**"
* Then send this list to the Sales Manager. \
  \&#xNAN;*For instance, I will send it to a specific email: **"<dung@ntd.asia>"***
* Using the **Create HTML table {}** action of **Data Operation** is to generate a table from Dataverse records.

{% hint style="info" %}
My steps:\
\&#xNAN;*<mark style="color:green;">**Schedule Flow -> Get List rows (from Dataverse) -> Create HTML Table -> Send Email (V2)**</mark>*
{% endhint %}

First of all, I have the list of ***Active Deals*** below and I expect the system will send 2 Deals with the **New** Status to my email **"<dung@ntd.asia>".**

<figure><img src="https://4233060750-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjhtQupP7ACZVtv3cCNCr%2Fuploads%2FMzzZ2PZPxdjtTDwC2q1e%2Fimage.png?alt=media&#x26;token=f55e1645-5680-4444-9261-b7f0c8499028" alt=""><figcaption><p>List of dealss</p></figcaption></figure>

## Creating Power Automate

In my solution, choose **Cloud Flow** > click **New** to create

<figure><img src="https://4233060750-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjhtQupP7ACZVtv3cCNCr%2Fuploads%2FS2PMuVMQTynQq3J9b4Tc%2Fimage.png?alt=media&#x26;token=bb3f27a1-770d-4c94-a11e-ca07f2b1634d" alt=""><figcaption><p>Scheduled Cloud Flow</p></figcaption></figure>

After creating, I added new step **"List rows"** from "Dataverse" > select my table **Deal** and set **Filter** for this step.

<figure><img src="https://4233060750-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjhtQupP7ACZVtv3cCNCr%2Fuploads%2FwY4nhSqiYyVsj3UmmNMe%2Fimage.png?alt=media&#x26;token=1044f2d3-83f6-4339-b69d-214f2f8e9d98" alt=""><figcaption><p>List Rows: Deals has New status</p></figcaption></figure>

{% hint style="info" %}
My sample, I filter Deals has Status Reason = "New"' ==> *<mark style="background-color:orange;">**statuscode eq**</mark>*<mark style="background-color:orange;">**&#x20;**</mark><mark style="background-color:orange;">**1**</mark>
{% endhint %}

## **\*\*Action: Create HTML Table {}**

In the 3rd step, I added an action <mark style="background-color:green;">**Create HTML Table {}**</mark> in **"Data Operation"**

<figure><img src="https://4233060750-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjhtQupP7ACZVtv3cCNCr%2Fuploads%2FxpOHUsWvTrJkFzRrWTA0%2F_create_html_table_deals.gif?alt=media&#x26;token=38745a96-0ace-46b5-8494-3a49c4748d8f" alt=""><figcaption><p>Action: Create HTML table from "List rows Deals" step</p></figcaption></figure>

Run testing and check the Output of step **"Create HTML table".** \
Because I selected the option <mark style="background-color:orange;">**Automatic**</mark> of ***Columns,*** so all columns of the **Deal** entity will be shown below.

<figure><img src="https://4233060750-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjhtQupP7ACZVtv3cCNCr%2Fuploads%2FNGa4VJhWgKUs394cuj3S%2Fimage.png?alt=media&#x26;token=2d5a1181-4a55-4250-a360-8fa197dd628f" alt=""><figcaption><p>The output of step "Create HTML table"</p></figcaption></figure>

Then I edit the option **Column** to <mark style="background-color:orange;">**Custom**</mark>**&#x20;->** and create the custom mapping for the table

<figure><img src="https://4233060750-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjhtQupP7ACZVtv3cCNCr%2Fuploads%2F5NU5rOsGJ9HSesM3CihG%2Fimage.png?alt=media&#x26;token=74f90313-ea18-4435-8bdf-5da0f3382123" alt=""><figcaption><p>Custom mapping</p></figcaption></figure>

After using custom mapping, we have the result:

<figure><img src="https://4233060750-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjhtQupP7ACZVtv3cCNCr%2Fuploads%2Fwss60QFhnBymfC48yXRu%2Fimage.png?alt=media&#x26;token=177f5e35-fc19-48cb-944e-53a35cde968c" alt=""><figcaption><p>The output of step "Create HTML table": Using Custom Mapping</p></figcaption></figure>

## Add step Send Email (V2)

I added the **Send Email (V2)** to the final step. In this step, I used the **Output** of action **"Create HTM table {}"** and added it to the email's body.

<figure><img src="https://4233060750-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjhtQupP7ACZVtv3cCNCr%2Fuploads%2FA7QyjVWalOfNK6OdssAj%2Fimage.png?alt=media&#x26;token=2b174410-de84-4236-b198-f19020385e90" alt=""><figcaption><p>Final Power Automate</p></figcaption></figure>

## First Testing...

After finishing the first version, I tested and saw the table has no border:

<figure><img src="https://4233060750-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjhtQupP7ACZVtv3cCNCr%2Fuploads%2FAR6bAMdDBY3AStzdEZ1h%2Fimage.png?alt=media&#x26;token=280e35e3-4335-4df0-97a4-210ef5a67f80" alt=""><figcaption><p>1st version -Default table has no border</p></figcaption></figure>

## \*\*Using Compose {} action & Final Flow

Then, I edit my Power Automate and use the action **Compose {}** of **Data Operation.** This action I used this to add **a border** for the table.

{% hint style="info" %}
I used the expression ***Replace()*** to take the table and replace the reference to the table object to include a format style.&#x20;
{% endhint %}

My expression:

```html
replace(body('Create_HTML_table'),'<table>','<table border=”1″>')
```

And the latest version of Power Automate, in the email body, I used the Output of step **"Compose".**

<figure><img src="https://4233060750-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjhtQupP7ACZVtv3cCNCr%2Fuploads%2FZfyN1VcwlcAAPUb9ONJR%2Fimage.png?alt=media&#x26;token=b286dd72-c4fc-4a85-8952-7b3e412c4cc2" alt=""><figcaption><p>Latest version - using "Compose {}" and "Replace ()"</p></figcaption></figure>

-> Running Test and check the result: The table has a border :)

<figure><img src="https://4233060750-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjhtQupP7ACZVtv3cCNCr%2Fuploads%2FiCepVXsg3EzYOCH70NZK%2Fimage.png?alt=media&#x26;token=27abe376-269b-4689-8b5f-81f699491e76" alt=""><figcaption><p>The table with border.</p></figcaption></figure>

Thank you and hoping well. :tada:\
\&#xNAN;**\[NTD]yns.asia**\ <mark style="color:red;">...</mark>[<mark style="color:red;">invite me a cup.</mark>](https://ko-fi.com/ntdyns/?ref=qr\&amp;v=2) :coffee: Thank you. :heart:
