Get Notified For List Item Changes Using Power Automate

Introduction

In this article, let's learn about how to find which columns have been updated in the SharePoint list item. We will make use of Power Automate to get these details. We will generate a table of columns which have been changed and send a notification to the user.

Implementation

Step 1 - SharePoint List

Let's create a SharePoint list named "Employee Details" having three columns: Title, Full Name, and Age

Step 2 - Power Automate Trigger

Let's use the trigger as When an item or a file is modified because we need to get the details only when the item is modified

Power Automate Trigger

Step 3 - Get Item Changes

We need to find out which columns have been updated. To find that, we will first get the changes made by the user. Use the action Get changes for an item or a file and use the below values:

  1. Id: ID of an item that is updated. So this will be triggerOutputs()?['body/ID']
  2. Since: Here we need to provide the version number from which we need the item changes. For example, if you have updated the item from version 9 to 10, you need to enter 9 in this field. To make it dynamic use below formula to get the previous version of the item. 
    sub(int(triggerOutputs()?['body/{VersionNumber}']),1)

Get item changes

Step 4 - Get Previous Version Details

We are going to generate a table with old and new values of the column. To do that, we will need previous version item details (column values). To get the previous version details, we do not have a direct action available in power automate. We will make use of HTTP request method to make a REST api call as shown below:

  1. Method: GET
  2. Uri: /_api/web/lists/getByTitle('Employee Details')/items(<ID>)/Versions(<PREVIOUS VERSION>)
    1. <ID> = triggerOutputs()?['body/ID']
    2. <PREVIOUS VERSION> = outputs('Get_changes_for_an_item_or_a_file_(properties_only)')?['body/SinceVersionId']
  3. Headers:
    1. accept = application/json
    2. odata = nometadata

Get previous version details using HTTP request

Step 5 - Parse JSON

At this point, we need to parse the JSON of Body of Step 4 so that we can read the old value of the columns. To do this, you will need the JSON schema.

  1. To get the schema, first save the flow and trigger it by modifying the list item.
  2. Then open the flow history and expand the action mentioned in step 4
  3. Click on Show raw outputs
  4. Copy the entire schema from body curly brackets as highlighted in the below screenshot

    Get JSON Schema
     
  5. Let's resume editing the flow and add the action called as Parse JSON. Then click on Generate from sample schema

    Content: body('Send_an_HTTP_request_to_SharePoint')

    Parse JSON
  6. Paste the copied schema and click on Done

Step 6: Filter array to get only modified column names

Now we need to filter the array to get only modified column names from step 3. To do that, we will use the action called Filter array and values as below:

From: split(string(outputs('Get_changes_for_an_item_or_a_file_(properties_only)')?['body/ColumnHasChanged']),',')

Filter array

Step 7: Generate Array of Changed columns

Now we will generate an array of changed columns so that we can create a table out of it. Let's initialize an array and append values as shown in below screenshot:

Generate array of changes

Step 8 - Create HTML Table

Let's use the action Create HTML table to create the table out of array variable. 

Create HTML table

Step 9 - Send email Notification

Now let's send an email notification to the user for the column value changes. use the Output of Create HTML table action in the email body.

You can also use custom CSS to style the table.

Send email notification

Output

Here is the entire flow screenshot:


Similar Articles