Access Flow Run History within a Record, Revisited with Cloud Flow Run History in Dataverse

Back in 2020, I wrote about how to access flow run history within a record by adding logging steps to every cloud flow, and a follow-up post on how to get the flow run by using the record ID as a parameter. Both approaches worked, but they had the same drawback: every flow had to be changed to log its own run, or I had to dig through the run history to find the run for a particular record.

Since then, Microsoft has added cloud flow run history in Dataverse. Every run of a solution-aware cloud flow is written to the system Flow Run (flowrun) table, which is an elastic table. In 2024, I also wrote about using Dataverse elastic tables in Power Automate cloud flows, which covers how to populate a lookup to the Flow Run table with the partition ID.

In this blog post, I combine the two and rebuild the 2020 solution so that the flows being monitored need no changes at all.

TL;DR: A scheduled cloud flow reads the new rows in the system Flow Run table every hour, works out which record triggered each run, and creates a Custom Flow Run activity linked to that record. The run history then appears on the record's timeline (or in a subgrid), just like the Background Processes view used to show for classic workflows.


What changed since 2020

2020 solutionUpdated solution
Where the run data comes fromExtra steps added to the end of each flow (or a child flow)The system Flow Run table (cloud flow run history in Dataverse)
Changes to the monitored flowsEvery flow needs the logging stepsNone
Run duration, status and errorCalculated inside the flowRead from the Flow Run row
When the record is loggedAt the end of the runWithin an hour (scheduled logger)

Why not just use the Flow Run table?

The Flow Run table already has the start time, end time, duration, status, error code and error message of each run. But it does not tell you which record triggered the run, so it cannot be shown on the record. On top of that, Flow Run rows are deleted automatically after the time to live, which is 28 days by default.

ⓘ Note

Only solution cloud flows, with their definitions in Dataverse, can have their run history stored in Dataverse. By default, flow run data is stored for 28 days (2,419,200 seconds). The time to live can be changed in the Power Platform admin center (28 days, 14 days, 7 days or Disabled) or in the FlowRunTimeToLiveInSeconds column of the Organization table.

Source: Manage cloud flow run history in Dataverse

So the logger copies the useful columns into a custom activity table, adds the triggering record and keeps a lookup back to the Flow Run row while it still exists.

Solution components

The solution is available in my GitHub repository (managed and unmanaged). It contains:

  • Custom Flow Run (lzw_flowrun): an activity table, so that the runs can be shown on the timeline and linked with Regarding
  • Flow Run History Logger - Scheduled: the cloud flow that does the logging
  • Flow Trigger (lzw_trigger): a choice for Create, Update, Delete and Select
  • Two connection references: Microsoft Dataverse and HTTP with Microsoft Entra ID (preauthorized)
Flow Run History Logger solution components

These are the columns captured on each Custom Flow Run record:

ColumnSource
SubjectFlow name and run ID
Flow Run (lookup)System Flow Run row (until it expires)
Flow Run URLLink to the run in Power Automate
Actual Start / Actual EndFlow Run start and end time
Duration (ms), Run Status, Error Code, Error MessageFlow Run
Flow Run Created OnFlow Run created on (used as the watermark)
TriggerCreate, Update or Delete from the trigger's SdkMessage, or Select for manual runs
Trigger Table, Trigger Record IDTrigger inputs and outputs
Triggering UserRunAsSystemUserId from the trigger outputs
RegardingThe triggering record, when the table supports it

How the logger flow works

Flow Run History Logger - Scheduled cloud flow

1. Find where it left off

The flow gets the latest Custom Flow Run record ordered by Flow Run Created On and uses it as the watermark. On the very first run, there is no record yet, so it goes back 28 days (the default time to live of the Flow Run table).

if(empty(outputs('Get_Latest_Logged_Flow_Run')?['body/value']),
   addDays(utcNow(), -28, 'yyyy-MM-ddTHH:mm:ssZ'),
   first(outputs('Get_Latest_Logged_Flow_Run')?['body/value'])?['lzw_flowruncreatedon'])

2. List the new flow runs

The List rows action on the Flow Run table gets the runs created after the watermark, oldest first, and expands the Workflow lookup to get the flow name and the ID used by the Power Automate API. Scheduled flows are excluded because they are not triggered by a record (and that also excludes the logger itself).

Filter rows: createdon gt @{outputs('Watermark')} and triggertype ne 'Scheduled'
Sort by:     createdon asc
Expand:      Workflow($select=workflowidunique,name)

3. Find the triggering record

This is the missing piece in the Flow Run table. For each run, the flow calls the Power Automate API with the HTTP with Microsoft Entra ID (preauthorized) connector to get the run details, which include links to the trigger inputs and outputs.

GET https://api.flow.microsoft.com/providers/Microsoft.ProcessSimple/environments/@{workflow()['tags']['environmentName']}/flows/@{items('Apply_to_each_Flow_Run')?['workflow']?['workflowidunique']}/runs/@{items('Apply_to_each_Flow_Run')?['name']}?api-version=2016-11-01

From the trigger inputs and outputs of a Dataverse trigger, the flow reads:

  • the table name from subscriptionRequest/entityname in the inputs
  • the record ID from ItemInternalId in the outputs
  • the message (Create, Update or Delete) from SdkMessage
  • the user who triggered it from RunAsSystemUserId

ⓘ Important

The run details endpoint (api.flow.microsoft.com with api-version 2016-11-01) is not documented by Microsoft, so it may change without notice. The user who owns the HTTP connection also needs access to the run history of the flows being logged (owner, co-owner or admin), and a premium Power Automate licence because of the HTTP action.

4. Create the Custom Flow Run activity

The flow first checks whether the run has already been logged (by the run name), so that a rerun does not create duplicates. Then it creates the Custom Flow Run record. The lookup to the Flow Run table needs both the GUID and the partition ID, as explained in my elastic tables post.

flowruns(flowrunid=@{items('Apply_to_each_Flow_Run')?['flowrunid']},partitionid='@{items('Apply_to_each_Flow_Run')?['partitionid']}')

5. Set Regarding

Regarding is set only when the triggering table has activities enabled and is not an activity itself, and the message is not Delete (a deleted record cannot be linked). The flow checks the table metadata once per table and caches it in a variable. For all other tables, Trigger Table and Trigger Record ID still identify the record.

Each run is processed in a Try and Catch scope. If one run fails to log, the flow carries on with the rest, lists the failed runs in its error message and ends as Failed, so it shows up in the run history of the logger.

Showing the runs on the record

Tables with activities enabled

Because Custom Flow Run is an activity, the runs appear on the timeline of the triggering record. You can also add a subgrid using the Regarding relationship (for example contact_lzw_FlowRuns) with the Flow Runs (Regarding Subgrid) view, which shows the status, start time, duration, trigger, error code, triggering user and the link to the run.

Flow Runs tab on the contact form

Clicking the Flow Run URL opens the run in Power Automate, which works as long as the run history still exists (28 days).

Custom Flow Run record details

Tables without activities

Not every table has activities enabled, and you might not want to enable them just for this. In that case, Regarding cannot be set, but the Trigger Table and Trigger Record ID columns can be used to filter a subgrid. A subgrid without a relationship ("All records") cannot be filtered by the current record in the form designer, so I used setFilterXml in the form's OnLoad event.

ⓘ Important

setFilterXml on a subgrid control is not part of the documented Client API. It is unsupported and may stop working after a platform update.

// UNSUPPORTED: setFilterXml is not part of the documented Client API.
var FlowRunSubgrid = FlowRunSubgrid || {};
(function (ns) {
    "use strict";
    var GRID = "FlowRuns";
    var TAB = "tab_flowruns";

    ns.onLoad = function (executionContext) {
        var formContext = executionContext.getFormContext();
        var tab = formContext.ui.tabs.get(TAB);
        var id = formContext.data.entity.getId();
        if (!id) {
            if (tab) { tab.setVisible(false); } // nothing to show until the row is saved
            return;
        }
        if (tab) { tab.setVisible(true); }
        applyFilter(formContext, 0);
    };

    function applyFilter(formContext, attempt) {
        var grid = formContext.getControl(GRID);
        if (!grid || typeof grid.setFilterXml !== "function") {
            if (attempt < 10) { setTimeout(function () { applyFilter(formContext, attempt + 1); }, 500); }
            return;
        }
        var recordId = formContext.data.entity.getId().replace(/[{}]/g, "").toLowerCase();
        var table = formContext.data.entity.getEntityName();
        var filter =
            '<filter type="and">' +
            '<condition attribute="lzw_triggertable" operator="eq" value="' + table + '" />' +
            '<condition attribute="lzw_triggerrecordid" operator="eq" value="' + recordId + '" />' +
            '</filter>';
        grid.setFilterXml(filter);
        grid.refresh();
    }
})(FlowRunSubgrid);

To use it:

  1. Add a tab named tab_flowruns to the main form with a subgrid named FlowRuns that shows All records of Custom Flow Run, using the Flow Runs (Record Subgrid) view.
  2. Add the script as a web resource (it is in the repository as samples/FlowRunSubgridFilter.js) and register FlowRunSubgrid.onLoad on the form's OnLoad event with Pass execution context ticked.
Flow Runs tab on a table without activities, filtered with setFilterXml

Installing the solution

  1. Download the managed solution from the release folder and import it.
  2. Create or select connections for the two connection references. The HTTP with Microsoft Entra ID (preauthorized) connection must use https://api.flow.microsoft.com as the base resource URL.
  3. Turn on Flow Run History Logger - Scheduled.
  4. Add the Custom Flow Run activity to the timeline, or add a subgrid, on the forms of the tables your flows trigger on.

The user who owns the connections needs organisation-level Read on the Flow Run table, so that the logger can see runs owned by other users. Flow Run records are user-owned and each user has their own partition.

Retention

The system Flow Run rows expire after the time to live, but the Custom Flow Run records do not, so the table keeps growing. I would set up a recurring bulk delete job in the Power Platform admin center (Settings > Data management > Bulk deletion) to delete Custom Flow Run records where Actual Start is older than 6 or 12 months.

Bulk delete jobs are solution-aware, but an imported job runs immediately, so I did not include one in the solution.

Known limitations

  • The run details call uses an undocumented API.
  • Only solution-aware flows write to the Flow Run table, so flows outside solutions are not logged.
  • According to Microsoft, the data stream behind the Flow Run table "isn't 100 percent lossless", so a small number of runs may never be logged.
  • Scheduled flows are not logged, because they have no triggering record.
  • Runs are logged within an hour, not in real time. In my testing, the Flow Run rows appeared one to three minutes after the run ended.

Summary

With cloud flow run history in Dataverse, the flows no longer need to log their own runs. One scheduled flow reads the Flow Run table, finds the triggering record from the trigger inputs and outputs, and creates a Custom Flow Run activity linked to it. The run history is then on the record where it is needed, without downloading the run history .csv file and searching for the record GUID.

You can download the solution from my GitHub repository.

Comments

Popular Posts