How to Extract and Send SharePoint List Item Comments via Email

Power Automate offers a range of capabilities to automate business processes, including the ability to extract data from SharePoint lists and send it via email. In this tutorial, we will leverage Power Automate to retrieve comments associated with a particular SharePoint list item and send them to an email recipient.

The example above shows a SharePoint list named "Acronyms" with list item 66 selected. The list item has three comments.
The example above shows a SharePoint list named “Acronyms” with list item 66 selected. The list item has three comments.

We will email the comments using a clean, professional-looking HTML table sent via Outlook:

The three list item comments are sent to an email recipient using Outlook
The three list item comments are sent to an email recipient.

How to Get a Single List Item’s Comments

By using the “Send an HTTP request to SharePoint” connector, it’s possible to retrieve comments associated with an item from a SharePoint list. We will need to extract just the comments data using an expression in a “Compose” action, and then use a “Select” action to choose the fields we want to include in the table, such as the comment author, date, and content. Lastly, we will use the “Create HTML Table” action to format the selected data into an HTML table before sending the comments to an email recipient.

1. Manual Trigger

In the flow that we will build, we will use a manual trigger.

In the flow that we will build, we will use a manual trigger (1).

2. The “Send an HTTP request to SharePoint”

Next, add a “Send an HTTP request to SharePoint” connector which we will configure below to retrieve the comments for a selected item from the SharePoint list.

In the example below I have selected my SharePoint site called "DemoSite", I have specified the SharePoint list called  "Acronyms" and I have selected list item ID 66 from which I want to retrieve the comments. I have also specified required properties for the Header

In the above example, I have selected the SharePoint site named “DemoSite” and the “Acronyms” list has been chosen. The comments related to item ID 66 will be retrieved, and the required properties for the Headers have also been specified.

Method: 
GET

Uri: 
_api/web/lists/getbytitle('<list name>')/items(<item-ID>)/Comments

Headers:

accept:
application/json;odata=verbose

content-type: 
application/json;odata=verbose

Make sure to enter the List name and list item ID into “Uri property” of the “Send an HTTP request to SharePoint” action as shown below:

The example above shows a SharePoint list named "Acronyms", the list item ID selected is 66.
The example above shows a SharePoint list named “Acronyms” with list item ID selected 66.

3. Extract the Comments from the “Send an HTTP Request to SharePoint” Action

Next we will extract the comments from the resulting output of the “Send an HTTP request to SharePoint” action using an expression in a “Compose” action:

Extract the comments from the resulting output of the "Send an HTTP request to SharePoint" action using an expression in a "Compose" action

The expression used in the Compose action is:

outputs('Send_an_HTTP_request_to_SharePoint')?['body']['d']['results']

The Expression: How it works

The reply or response from the “Send an HTTP request to SharePoint” is called the response object. The response object contains the “status code”, “headers” and a “body”. And buried within the body section of the response object we will find the list item comments.

The  "Send an HTTP request to SharePoint"  response object contains a "status code", "headers" and a "body"
The response object contains a “status code”, “headers” and a “body”

Below we see an example of a response body. The list item comments are actually found in the body within an array called “results”:

Showing the body of the  "Send an HTTP request to SharePoint"  response

We can extract the comments from the response object using the following expression:

Extract the comments from the response object using an expression

If we examine the array results array, we see that it does indeed contain the three list item comments. If no comments were found then the results array would be empty.

Examine the array "results"
The array “results” array contains the list item comments. In this example there are three comments.

4. Use a Select Action

In step 4 we use the “Select” action to choose the fields we want to include in the HTML table, such as the comment author, date, and the comment text:

The “Select” action to choose the fields we want to include in the HTML table, such as the comment author, date, and the comment text

Enter the following expressions in to the Select action:

Name:
item()?['author']['name']

Date:
formatdateTime(item()?['createdDate'], 'dd MMM yy')

Text:
item()?['text']

In the image below we see the properties that are selected for each comment:

In the image below we see the properties that are selected from the results array (which is stored in the Compose action)

The Select action produces the following output:

The output of Select action  containing the author name, date and comments

5. Create the HTML Table

We use the “Create HTML Table” action to format the selected data into an HTML table before sending the comments to an email recipient. The output of the Select action is used to create the HTML table:

Create HTML Table action

6. Add some HTML table formatting style code

This is the table formatting style code I used. I have provided the code below which you can copy-and-paste into your flow.

This is the table formatting style code I used.

Here is the code that you can copy-and-paste for the Compose Table Formatting Style action:

<style>
table {
  border: 1px solid #1C6EA4;
  background-color: #EEEEEE;
  width: 100%;
  text-align: left;
  border-collapse: collapse;
  table-layout: auto;
}
table td, table th {
  border: 1px solid #AAAAAA;
  padding: 10px;
}
table tbody td {
  font-size: 13px;
}
table thead {
  background: #1C6EA4;
  border-bottom: 2px solid #444444;
}
table thead th {
  font-size: 15px;
  font-weight: bold;
  text-align: left;
  color: #FFFFFF;
  border-left: 2px solid #D0E4F5;
}
table thead th:first-child {
  border-left: none;
}
</style>

7. Send the Comments using Email

This is the Send an email action that will email the nicely formatted HTML table. Pay close attention to the order of the Compose outputs in the email body or your HTML table styling wont be applied:

The Send an Email action. HTML table formatting code first, then the output of the Create HTML table next. Pay close attention to the order of the Compose outputs in the email body or your HTML table styling wont be applied.
Pay close attention to the order of the Compose outputs in the email body or your HTML table styling wont be applied

And finally, we see the email that was sent out:

Example email that was sent out.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Website Built with WordPress.com.

Up ↑

%d bloggers like this: