Marcel Lehmann

learn and find tipps & tricks around the powerplatform

How to track the current progress of a flow in the PowerApp

In some scenarios i or the user would like to see how far the Cloud Flow Process (PowerAutomate) is already after I started it via PowerApps.

Unfortunately it is not possible to use “Respond to PowerApps” multiple times to show me a status update in the PowerApp.

For this we can easily create a StateLog table and check it regularly via timer. Of course, it is important that we send an update to the StateLog entry after milestones in the flow. However, it is also possible that you do not update the entry as in the solution here, but that you create a new entry each time. this gives you other display options in the app.

Here you can download the solution and use it at your place.

What you need in your app for the implementation

  • Flow Trigger -> here button
  • Timer -> to refresh the Data
  • something to show the state -> here text & icons
  • List to write the State -> here SharePoint

Build a datasource with three columns

Here I use the default column “Title”, a text column GUID” (so I can filter by it later) and a number column “StateCode” (so I can do certain things later based on the StateCode)

create a flow in the similar format

It is important that the trigger is followed immediately by the “Create Item”. There you create an entry in the StateLog with the GUID (which you generate and transfer via PowerApp) and of course the StateCode with a naming of the status.

The scopes with the name “Flow Actions” are only symbolic. you can use any actions there. as soon as an important milestone is reached, you simply update the status (or create an additional entry in the statelog -> depending on the desired solution).

You can find the code to copy and paste the flowactions at the end of this post.

create your app

1. the trigger of the flow.
Here the flow is attached. I use here with “OnSelect” the function to store a GUID in a variable and then pass this GUID to the flow.

//generate GUID for selection
Set(varStateGUID,GUID());
//start Flow
wfState.Run(varStateGUID)

2. The timer
I use this to check the status in regular intervals (here duration 3000ms -> 3sec).

I have the following settings stored with me:

  • AutoStart: ‘!IsBlank(varStateGUID)’.
  • Repeat: ‘locCurrentState.StateCode<>3’ (variable is set OnTimerEnd)
  • Refresh(StateLog);UpdateContext({locCurrentState: LookUp(StateLog,GUID=Text(varStateGUID))})

In the last step mentioned above I refresh the data source and then read the current state via lookup and the GUID variable we created in step 1 and save it via updatecontext.

3. + 4. display of the status
here i chose the simple variant by displaying the status text. but it is also possible to display icons or other elements depending on the status code.

Flow-Code

{"id":"5d6770c8-725f-42a0-86a9-a13cc239d868","brandColor":"#8C3900","connectionReferences":{"shared_sharepointonline":{"connection":{"id":"/providers/Microsoft.PowerApps/apis/shared_sharepointonline/connections/shared-sharepointonl-2e2e173e-f314-4d56-afe3-20f134d359a6"}}},"connectorDisplayName":"Control","icon":"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIiIGhlaWdodD0iMzIiIHZlcnNpb249IjEuMSIgdmlld0JveD0iMCAwIDMyIDMyIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPg0KIDxwYXRoIGQ9Im0wIDBoMzJ2MzJoLTMyeiIgZmlsbD0iIzhDMzkwMCIvPg0KIDxwYXRoIGQ9Im04IDEwaDE2djEyaC0xNnptMTUgMTF2LTEwaC0xNHYxMHptLTItOHY2aC0xMHYtNnptLTEgNXYtNGgtOHY0eiIgZmlsbD0iI2ZmZiIvPg0KPC9zdmc+DQo=","isTrigger":false,"operationName":"LogState","operationDefinition":{"type":"Scope","actions":{"Create_item_-_Flow_started":{"type":"OpenApiConnection","inputs":{"host":{"connectionName":"shared_sharepointonline","operationId":"PostItem","apiId":"/providers/Microsoft.PowerApps/apis/shared_sharepointonline"},"parameters":{"dataset":"https://lehmannws.sharepoint.com/sites/lehmann.ws","table":"5fe8a63f-d26b-419e-a693-6687f7275ebf","item/Title":"Flow started","item/GUID0":"@triggerBody()['text']","item/StateCode":0},"authentication":"@parameters('$authentication')"},"runAfter":{},"metadata":{"operationMetadataId":"158862e4-3942-4c31-bcfb-023af6fa6179"}},"Flow_Actions_-_First_Block":{"type":"Scope","actions":{"Delay":{"type":"Wait","inputs":{"interval":{"count":5,"unit":"Second"}},"runAfter":{},"metadata":{"operationMetadataId":"061f09c0-5fc1-4490-96c3-a61a5ff64ca1"}}},"runAfter":{"Create_item_-_Flow_started":["Succeeded"]},"metadata":{"operationMetadataId":"457a1895-9a60-49ce-8833-c1e66425d566"}},"Update_item_-_first_actions_carried_out":{"type":"OpenApiConnection","inputs":{"host":{"connectionName":"shared_sharepointonline","operationId":"PatchItem","apiId":"/providers/Microsoft.PowerApps/apis/shared_sharepointonline"},"parameters":{"dataset":"https://lehmannws.sharepoint.com/sites/lehmann.ws","table":"5fe8a63f-d26b-419e-a693-6687f7275ebf","id":"@outputs('Create_item_-_Flow_started')?['body/ID']","item/Title":"first actions carried out","item/GUID0":"@triggerBody()['text']","item/StateCode":1},"authentication":"@parameters('$authentication')"},"runAfter":{"Flow_Actions_-_First_Block":["Succeeded"]},"metadata":{"operationMetadataId":"61ca671e-ef33-44ea-b22c-932b9468b964"}},"Flow_Actions_-_Second_Block":{"type":"Scope","actions":{"Delay_2":{"type":"Wait","inputs":{"interval":{"count":5,"unit":"Second"}},"runAfter":{},"metadata":{"operationMetadataId":"c0e22d53-063c-480c-8a6b-791726629a4b"}}},"runAfter":{"Update_item_-_first_actions_carried_out":["Succeeded"]},"metadata":{"operationMetadataId":"2a256fed-8839-4ca6-b209-0c54c798bde5"}},"Update_item_-_second_block_of_actions_completed":{"type":"OpenApiConnection","inputs":{"host":{"connectionName":"shared_sharepointonline","operationId":"PatchItem","apiId":"/providers/Microsoft.PowerApps/apis/shared_sharepointonline"},"parameters":{"dataset":"https://lehmannws.sharepoint.com/sites/lehmann.ws","table":"5fe8a63f-d26b-419e-a693-6687f7275ebf","id":"@outputs('Create_item_-_Flow_started')?['body/ID']","item/Title":"second block of actions completed","item/GUID0":"@triggerBody()['text']","item/StateCode":2},"authentication":"@parameters('$authentication')"},"runAfter":{"Flow_Actions_-_Second_Block":["Succeeded"]},"metadata":{"operationMetadataId":"1fa400b7-cf16-4270-8cc9-a8cf3b2a7e56"}},"Flow_Actions_-_Third_Block":{"type":"Scope","actions":{"Delay_3":{"type":"Wait","inputs":{"interval":{"count":5,"unit":"Second"}},"runAfter":{},"metadata":{"operationMetadataId":"e27fb99e-cf28-4ad2-8027-55566bed620f"}}},"runAfter":{"Update_item_-_second_block_of_actions_completed":["Succeeded"]},"metadata":{"operationMetadataId":"56369547-1b13-475b-b0e0-527f43ecd247"}},"Update_item_-_Flow_finished_-_third_block_processed":{"type":"OpenApiConnection","inputs":{"host":{"connectionName":"shared_sharepointonline","operationId":"PatchItem","apiId":"/providers/Microsoft.PowerApps/apis/shared_sharepointonline"},"parameters":{"dataset":"https://lehmannws.sharepoint.com/sites/lehmann.ws","table":"5fe8a63f-d26b-419e-a693-6687f7275ebf","id":"@outputs('Create_item_-_Flow_started')?['body/ID']","item/Title":"Flow finished - third block processed","item/GUID0":"@triggerBody()['text']","item/StateCode":3},"authentication":"@parameters('$authentication')"},"runAfter":{"Flow_Actions_-_Third_Block":["Succeeded"]},"metadata":{"operationMetadataId":"4b93bd92-88af-4610-9c23-340d5f872f7b"}}},"runAfter":{}}}

Published by

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

%d bloggers like this: