Add Power Automate History with SharePoint List Item

Published by Prateek Mangal on

At some point you must have experience an issue to identify Power Automate instances ran on a SharePoint List item to troubleshoot any problem with application. Power Automate can be Item Modified, File Properties Modified or Selected Item trigger. 

In this blog, We are going to explain you that how you can attach Power Automate (Flow) history with SharePoint List Item in an automated way. Also, you can customized this approach as per your project’s  requirements.

Please follow below steps to implement Power Automate history with SharePoint List item:
  1. Create a SharePoint List or use your existing SharePoint List
  2. Create two Multiline Text columns.
    • Flow History Rows  – Internal name of this column should be “FlowHistoryRows” and Rich Text property must be turn off.

      We will use this column to store text html table rows. It will be modified with new row every time if new instance is triggered. We can hide this column from list view.

    • Flow History Table – Internal name of this column should be “FlowHistoryTable” and Rich Text property must be turn on.

      We will use this column to store html table. It will be modified based on previous column. We need to show this column in list view as this will be our final objective in list view.

  3. Once we are done with SharePoint list, then we need to create a Power Automate. Here, we will create selected item trigger.
  4. As per picture above, we need to create two string variable in flow.
  5. Now we need to add GetItem connector to get value from list item for which trigger is done. We can get the value from selected item trigger as well. But if we are going to change the trigger of this flow then we need to add the references of columns in data operations again. Instead of using trigger output, we are using GetItem connector.
  6. Now we need to get the details of instance.
    • Parse JSON Workflow Instance Details – Using below expression we will get the flow instance details.
      • Content
        workflow()
      • Schema
        {
            “type”“object”,
            “properties”: {
                “name”: {
                    “type”“string”
                },
                “run”: {
                    “type”“object”,
                    “properties”: {
                        “name”: {
                            “type”“string”
                        }
                    }
                }
            }
        }
    • FlowURL – Generating URL of flow instance.
      • Input
        concat('https://us.flow.microsoft.com/manage/environments/Default-34cd94b5-d86c-447f-8d9b-81b4ff94d329/flows/', body('Parse_JSON_Workflow_Instance_Details')?['name'], '/runs/', body('Parse_JSON_Workflow_Instance_Details')?['run']?['name'])
    • CurrentDate – Current data and time of instance.
      • Input
        concat(formatDateTime(utcNow(), 'g'), ' UTC')
    • Set vFlowHistoryRows – We are appending new row every time when flow is triggered.
    • Set vFlowHistoryTable – With above variable “vFlowHistoryRows” we are constructing final html table.
      • Value @{variables(‘vFlowHistoryRows’)}
        DateFlow URL
  7. Final task is to update these variable values in their respective columns in SharePoint List item.

Now our Flow history flow is ready to test. As this is item selected trigger, then you need to run this flow from SharePoint List view. After running couple of instances our final output will look like:

We can customize this approach to create approval history table to log details like approver’s comments, date and name.

Also, we need to make sure that if we are using Item Modified trigger, then our flow should have trigger condition to stop re-triggering this flow as we are updating history using Update item connector.

If you like or implemented this approach, please provide your feedback.
Happy Learning!!

Care to Share?

Prateek Mangal

7 Years Experienced Information Technology Professional with a demonstrated history of working in the information technology and services industry. Skilled in SharePoint, Power App, Power Automate, Power BI, SQL, CSS, .NET, HTML, and REST API. 

0 Comments

Leave a Reply