How to: initiate a document approval directly in team files tab (using Power Automate)

The new Approval application is a very useful tool for multiple use cases that requires approval. One of it’s great benefits is that it brings the approval process directly onto Teams – where the users are. It simultaneously sends also the approval in email for users so they can choose where they act on the request. That is a true better together scenario that doesn’t force users to visit a another location.

However when it comes to starting an approval process with documents in team it lacks the out of the box capability to do it in a smart way. When you navigate to team files tab you don’t have the possibility to start a flow or even edit the metadata that would trigger a flow. However in this blog post I show how you can add a metadata column to team files that acts as a link that starts the flow!

Short overview

  • Power Automate Premium is needed to add a HTTP Request trigger
  • Link is added by SharePoint column formatting
  • Uses the Approvals-actions in Power Automate normally
  • Use Teams actions to get approval request comments from the initiator

Create the approval Cloud Flow

There are not that many steps in this one, but there are couple of tricks that are good to know

The first one is of course the one that requires the Premium-licensing for Power Automate: When a HTTP Request is received. You can find the trigger easily when you start creating a instant flow

When you select the HTTP Request trigger it defaults to POST-action. Use advanced options to select GET. When you save the Flow you will get your unique URL to flow activation.

You will be posting the FileID as a URL parameter. To extract it from the request add a parameter and use expression triggerOutputs()[‘queries’][‘FileID’] to extract the value. FileID is the parameter name, that I chose in my example.

Next you will retrieve the file from the library. I used the team site in this example and pass the FileID into Id -field using parameter-variable.

After getting the file info I retrieved the name of the file and also created a response to be returned to web browser so it doesn’t keep browser waiting. This is also a Premium action.

After that I asked for approval request comment from the user who initiated the request.

That GetComment part is done with Post an Adaptive Card to a Teams user and wait for the response.

In that card I ask the user to comment why the approval is started and save the response to MyComments that is used in Create an approval-action using expression outputs(‘GetComment’)?[‘body’][‘data’][‘myComments’]

The Item link is important – when you populate it with the link to the document it can be easily opened via the Approval application or via approval request in the email. Also populate other fields to your liking so get all the needed information to the approver to make it easier to decide the outcome.

Then the approval itself is managed in the Approval app or in email. After the approval is either approved or rejected the Flow continues. In the example I only update the document metadata with information – but this is the right spot to protect the document (permissions) and/or copy it to some protected location that the contents can not be changed anymore.

Add Column Formatting to team files (SharePoint library)

To prepare the SharePoint library you need to go to team files tab and open it in the SharePoint. Then add metadata columns you like, I used the column name “Approve this” (hyperlink) and Approval outcome (multiple lines). Once added select the menu from “Approve this” column and open Format this column.

You will then have the option to edit the column formatting on the right. You need to add the information there that translates to a actionable link with the file id included.

To make it easier here is the snippet without identifiers. You get the base URL from the HTTP Request trigger in the Flow:

  • Choose the text output of the field by putting the text of your liking to txtContent-part: “txtContent”: “Request Approval”,
  • Put your HTTP Request URL to href part. “href”: “=’YourURLHere’
  • Add a parameter there right after the question mark. Just add FileID=’ + [$ID]+’& between ? and api-version.
{
    "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
    "elmType": "a",
    "txtContent": "Request Approval",
    "attributes": {
       "target": "_blank",
       "href": "='https://urlhere.azure.com/workflows/[some id values]/triggers/manual/paths/invoke?FileID=' + [$ID]+'&api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=[some code here]I'"
    }
 }

When you click save you can see the outcome that has a link customized to each document.

Approval request process in Teams

When you open the team and navigate to files tab you can see the same view there!

This allows the user to initiate the Request Approval flow directly via Teams just by clicking the column!

As per flow the user receives a Flow bot message to comment the approval request.

Once the user hits Submit the flow progresses and creates a Approval request. It fires the notification to approver in Teams that opens the Approval application directly.

As can be seen in the dialogue the information we added in the approval creation is visible to users – including the approval request asked via the Flow bot. The link to the document opens it directly in the web browser so approver can review the contents easily. This looks really good! Let’s hit Approve.

The next fires up another notification that lets to see the approval outcome. This is also the view that holds the information who approved, what and when so there is a solid trace in case it needs to be investigated later.

As determined in the Flow the approval information is written to the file metadata for demo purposes. It is visible in team files in this case.

The Conclusion

Using a bit of SharePoint and Power Automate skills with Premium licensing it is possible to create document approval flows that can be initiated from inside Teams – making it really easy for users to initiate document approvals when using Teams Desktop or Teams web version. Mobile Teams does not, unfortunately, display file metadata.

It is good to keep in mind that the http GET request is a anonymous & public link. Anyone can use that link unless you pay attention to that. You may want to read this article about possibilities to secure the API – you might want to use Azure API Management for that for example.

Using document library column formatting it would be possible to create other kind of flows as well: updating metadata, moving the document forward in the process etc.

Learn more about column formatting in SharePoint and HTTP Request trigger & from here also.

In order to avoid the requirement for Premium licensing it would be good to create a Power App that would list team files and when initiate the flow via that. That is not included in this blog post – I get back to that in some time later.

This mechanism with HTTP Request is one way to integrate an external system (legacy, backend) approvals with Microsoft Teams. The request can be a simple GET with parameters or POST/PUT with a payload body. This method enables to initiate the Cloud Flow in Microsoft 365, to be used for example in approval processes. Reply mechanism can vary from a HTTP Response to various other ways. Power Automate is an incredible toolbox in Microsoft 365!

Approvals are a really powerful feature in Microsoft Teams. You should also read my good friend’s , who is also a fellow MVP, Chris Hoard’s posts concerning Approval processes:

20 thoughts on “How to: initiate a document approval directly in team files tab (using Power Automate)

  1. Thanks for this post. Really simple but also impressive what can be done (and definitely needs reapplication on my side).
    One question though: as mentioned in your post, all the approvals can be found in the approval app – unfortunately the list will get very long quickly and it is hard to find the needed entry (as you can‘t add any fields to classify).
    Is there a way to sear / filter or link to that individual entry? My dream would be that the Teams list contains directly a link to the approval…

    Like

    1. Nothing is stopping you from adding some customizations when you create the approval process. Every approval comes with a link to approval so you could be adding them to a list/Dataverse and build your own Approval app on top of it to keep your custom processes ins a well organized location. You could create a list in Teams(SharePoint) that has a column with a list to approval. That takes you to the web page in Flow where you can submit the decision.

      In the actual Approval app the possibilities are more limited. You can filter the view to show only custom approvals and if you build your process with those you get some other approvals out of the view. However I would think that the list of open approvals would be limited to most of people. You can filter the App to show only “requested” approvals -> that are open and require action from your part.

      But otherwise I agree – it would be awesome to be able to add some custom fields to the Approval request and they would reflect in the app as columns/filters/sorting. It is perhaps to think that this Approval is app is at version 1.0 and hopefully there will be other capabilities (like document esigning ) that will make it better.

      Like

      1. Thanks for your quick reply.
        One follow up question: you said that each approval comes with a link to the approval – unfortunately I cannot find that in Power Automate – any hint where to find it?
        Thanks!

        Like

  2. If you use Power Automate action “Create an approval” you can see in it’s dynamic values Respond link that takes you to Flow portal to approve/reject it. You can add Wait for an approval action later when you have added approval data to storage or done other steps you want to perform before starting the wait.
    If you use action “Start and wait for an approval” that link doesn’t exist (since it is already waiting for the response).

    Like

    1. ah yes, true – did not think about that… That works fine now!
      Follow up question: is there also a way to get a link to the result? I can link to the flow approval history page but I did not find a way to link to a specific approval result. Would be helpful as audit trail without having to add/copy all the fields to my list.There is an Approval ID available but so far had no luck using that to link to the details.

      Like

  3. I don’t know if there is such a way. But how about writing that result to a list after approval, in the Flow? Of course the approval database is more traceable but list (or any database) is something that you can manage.

    Unfortunately I don’t have time right now to dig into that detail. It may be possible that opening the app/Flow page is not very easy.

    Like

    1. Vesa, thanks once again.
      Yes, setting up a list is actually what I am doing already and I did not find another solution. So I will just stay with this and play again with it if I read something new…

      Liked by 1 person

  4. Really good post and useful. Thank you again.
    May I ask if it is possible to get the URL or Team info from where it was triggered from so I can dynamically use that in the flow. For example when I fetch the ID i need to select the document path and so on in the Get file properties trigger, is it possible to auto get them as we do with the ID for the file?

    I’m trying to achieve to only have one flow that i re-use on multiple teams and not create a new flow for each Team.

    Liked by 1 person

    1. The source team or some other ID could be put to the link as a another parameter , just like when adding the document ID. The formatting needs to be done separately to each doclib but you could use a single endpoint.

      Liked by 1 person

      1. Thank you for answering. I’m new to this and i wonder if you could point me in the right direction to format Path.

        Like

  5. Could you point me in the right direction on how to get the source team or Link url for the file, dont really know how to work with the formatting new at this 🙂

    Like

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 )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.