Part Two – Using Power Automate show the most recent comment from SharePoint text fields instead of “View Items”

Problem

As my previous blog post on the same topic, what if there is an existing list which has the multi text ‘Comments’ field.

How to take the last comment and copy in the ‘MostRecentComments’ field for all items in the existing list?

Step by Step Solution

Step # 1 – Create a Manually Trigger flow.

Step # 2 – First let’s get all items IDs (plus required fields) from the list using ‘Send an HTTP request to SharePoint’.

*** Uri ****
_api/web/lists/GetByTitle('TestMirrorMultiText')/items?$select=ID

*** Headers ***
{
   "Accept": "application/json;odata=nometadata"
}

***** The output of the action will be an Object with an Array ***
{
  "value": [
    {
      "Id": 5,
      "ID": 5
    },
    {
      "Id": 6,
      "ID": 6
    }
  ]
}

Step # 3 Iterate over each array item and get the Comments field with “versions“.

Note: Apply each of the “value” property of the above step and it is an array.

**** Uri *** Note: we just need multi text Comments field and it's versions.

_api/web/lists/GetByTitle('TestMirrorMultiText')/items(@{items('Apply_to_each')?['ID']})/versions?$select=Comments

*** Input Headers ***
{
   "Accept": "application/json;odata=nometadata"
}

*** Output for each ID will be like following ***
Note: There will be nulls, we need to eliminate nulls in the next step.
{
  "value": [
    {
      "Comments": null
    },
    {
      "Comments": "This is a test2"
    },
    {
      "Comments": "Lorem Ipsum ...."
    }
  ]
}

Step # 4 Within the ‘Apply Each’ loop filter the null from the Comments array.

*** From ***
Note: we need to get the Value array
outputs('Send_an_HTTP_request_to_SharePoint_2')?['body']?['Value']

*** In the condition ***
Note: items is a special function to access each item.
item()?['Comments']
** The output of the Filter will be with Comments with *no* null values 

Step # 5 Final step in the ‘Apply Each’ to update the list.

*** The MostRecentComments field will be set with the first value 
of the filtered array ***

body('Filter_array')?[0]?['Comments']

Results

The final result will be have last comment in the ‘MostRecentComments’ field. This blog post is a technique to update your all items in the existing list. Once you have done that you will not have to run this flow. From my previous blog post the item added and modified event will update the ‘MostRecentComments’ correctly.

About Pankaj

I am a Developer and my linked profile is https://www.linkedin.com/in/pankajsurti/
This entry was posted in Power Automate. Bookmark the permalink.

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