in Flow, SharePoint

How to track the flows that created the items in your SharePoint list

Scenario

You might have asked yourself the following question: how do I know which flow created the items in my SharePoint list?

The answer is simple: you don't and you shouldn't expect Flow to have this kind of capability OOTB. The reason is because Flow is a data integration and workflow development service – it uses the APIs of the target services it connects to, so it does what the APIs is allowing it to do.

If you want to track the flow that made changes in your SharePoint list, for example, you have to alter your list and create one column to track the flow run that created the item and, optionally, another column to track the flow run that modified the item.

The method explained in this article applies to any DBMS, DMS, API, or application, such as Excel, where you can store data. For the sake of simplicity, I'm using a SharePoint list as an example.

Modifying the SharePoint List

I already built a SharePoint list that stores random strings. To this list I've added a hyperlink column Created Flow Run Link where I will store the flow run URL:

Modifying the Flow

My flow is pretty simple. It gets random texts from Bacon Ipsum and stores them in the list.

The only thing that I have to modify here is the Create item action. I will use WDL workflow functions to build a link and pass it to the Created Flow Run Link field.

A flow run URL looks like this:

https://us.flow.microsoft.com/manage/environments/Default-cf811315-a2b6-44a6-94c6-1d78a2b08e8d/flows/ee8603be-70b6-4429-9d97-2fb72cf68d2d/runs/08586503576773156173802381983CU99

To build the URL, I will need the environment ID, the flow ID, and the run ID. The URL also contains the region, but I will ignore it because the region is resolved automatically when we access https://flow.microsoft.com

https://{region}.flow.microsoft.com/manage/environments/{environmentID}/flows/{flowID}/runs/{runID}

If you read the documentation, the workflow() function returns all the details about the flow itself during run time.

  • workflow().tags.environmentName returns the environment ID
  • workflow().name returns the flow ID
  • workflow().run.name returns the run ID
{
  "id": "/workflows/009d6d1ea5a845918c13d48c4552697d",
  "name": "ee8603be-70b6-4429-9d97-2fb72cf68d2d",
  "type": "Microsoft.Logic/workflows",
  "location": "westus",
  "tags": {
    "flowDisplayName": "Insert random text in a SharePoint list",
    "environmentName": "Default-cf811315-a2b6-44a6-94c6-1d78a2b08e8d",
    "logicAppName": "ee8603be-70b6-4429-9d97-2fb72cf68d2d",
    "environmentFlowSuspensionReason": "Default:2Dcf811315:2Da2b6:2D44a6:2D94c6:2D1d78a2b08e8d-None"
  },
  "run": {
    "id": "/workflows/009d6d1ea5a845918c13d48c4552697d/runs/08586503576773156173802381983CU99",
    "name": "08586503576773156173802381983CU99",
    "type": "Microsoft.Logic/workflows/runs"
  }
}

To create the URL I am using the following expression: concat('https://flow.microsoft.com/manage/environments/', workflow().tags.environmentName, '/flows/', workflow().name, '/runs/', workflow().run.name)

Running the flow once will result in 5 random strings created in the Random Strings list in SharePoint:

Clicking the flow run link takes us to the actual flow run that created the item:

If I want to have a clearer image of what's been created on each flow run, I can edit the view and group by Create Flow Run Link column:

And the view will look like this:

Write a Comment

Comment

Webmentions

  • How to get all messages in a Yammer group using Microsoft Flow - Alex Tofan's blog

    […] ID. I've added an array containing two messages below – yes, I've use bacon ipsum again […]