“What options do I have to find the approval task related item to update the approval history column from a Power Automate flow?”
You probably already know about the limitation of 30 days per a flow run. If a flow takes more than 30 days to finish, it’ll stop automatically. Which might be a problem for approval processes, hence you might need a workaround.
There’re already a few solutions out there. You can have a separate “waiting flow” that you’ll resubmit, or you can track the approvals Dataverse table. Yet I feel there’s one part missing – how do you get the related item? The one that triggered this approval, where the approval should continue?
Storing the ApprovalId somewhere else
While it might be easy to implement this solution on a single list – you just store the ‘Approval Id’ in a column, it’s not often the real world situation. The Approvals are shared across the whole Power Platform environment. It can contain tasks for tens of solution, and it’s not realistic to check all the lists / tables for a specific Approval Id.
Although, nobody said that it must be directly in the list with the request. Instead of storing it in each of the lists, you could create a “global” list for all the IDs. All it takes is a single list where you create / update an item with each approval step.
Store the Approval Id, where is the item located, and the item Id, and once users complete the task you’ll know exactly where to look.
Finding the request through the item link
If you’re not very keen on the idea of storing the task id in a list with every flow, after each approval step, you can look into the task itself.
As Approvals are a standalone application, there’s no direct connection to any request. The only way to connect them is in the ‘Item Link’ column – a link you add while creating the task.
Let’s consider two situations for this article – one where you reference a SharePoint item directly, another where you use PowerApps.
Link to SharePoint item
If the request is stored in a SharePoint list and you’re sending users directly to SharePoint, the link has a fixed format. For example:
https://xxx.sharepoint.com/sites/Approval_DEV/_layouts/15/listform.aspx?PageType=4&ListId=de3d9496%2D157e%2D4060%2Da950%2D0102ee905b43&ID=17&ContentTypeID=0x0100F60C4FC3B8F73B46950483AFBB1D273E
When you look on it properly you’ll see it contains everything you might need. It starts with the site url. Then there’s the ListId and the Id of the item. And since it’s a string you can easily extract it in a flow.
Get the site by taking everything before the ‘/_layouts’…
split(outputs('Get_a_row_by_ID')?['body/msdyn_flow_approval_itemlink'],'/_layouts/')[0]
…list id by taking everything between ‘ListId=’ and ‘&’, while replacing ‘%2D’ with ‘-‘…
replace(split(split(outputs('Get_a_row_by_ID')?['body/msdyn_flow_approval_itemlink'],'ListId=')[1],'&')[0],'%2D','-')
… and item Id between ‘ID=’ and another parameter starting with ‘&’.
split(split(outputs('Get_a_row_by_ID')?['body/msdyn_flow_approval_itemlink'],'ID=')[1],'&')[0]
Once you have these 3 pieces of information you can easily use it later in the flow.
Link to PowerApps application
The second options is when you avoid the SharePoint user interface. Instead of sending users to SharePoint to check the task, you might send them to a PowerApp. The link to SharePoint item is replaced with a link to PowerApps app with a parameter, e.g.
https://apps.powerapps.com/play/e/8b42720b-def8-ebdd-b554-059e9f50ce53/a/1341433b-a838-46df-92ad-9f4d88ed9fc1?tenantId=c3adda97-555b-44f6-9fbb-ecf0395f334b&hint=cae964cf-ca91-4841-b0ac-88105719af9e&sourcetime=1720957661719&RequestId=5
The only information you have here is the item Id, your custom parameter. There’s no site url, no list name/Id, just the item Id. That means you must store it somewhere else.
This approach will need another “global” list, but this time a simplified one. It doesn’t need an entry with each new approval task, just a mapping between the PowerApps app Id and their source lists.
With this list in place you can always extract the PowerApps Id from the link and find the site / list in the configuration list.
split(split(outputs('Get_a_row_by_ID')?['body/msdyn_flow_approval_itemlink'],'/a/')[1],'?')[0]
Add the item Id from the parameter and you’ll have all the information necessary to identify the request.
split(outputs('Get_a_row_by_ID')?['body/msdyn_flow_approval_itemlink'],'RequestId=')[1]
Summary
Since the Approvals application is not connected to any specific resource, you can use it to approve anything. That’s a lot of flexibility, but on the other side it might take some work to find out what exactly were you approving.
In this article I explained how to find the task related item in a Power Automate flow. The simplest option is to store the Approval Id directly in the item, but that’ll work only for a single solution. That’s why I’d recommend the other one, where you extract it from the item link. Let it be links to SharePoint lists or to PowerApps, or combinations of both, with a bit of parsing you can get all the information you’ll need.