Tuesday, January 25, 2022

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

Must read

Vesa Nopanenhttps://myteamsday.com/
MVP for Office Apps & Services (Teams & Collaboration focus), Principal Consultant in Office 365 and Modern Work. Extremely passionate about Microsoft Teams's power to change how people work together. Helping and coaching customers to find benefits, solutions and value when adopting new tools, methods, ways or working and practices into daily work-life equation. I am always eager to challenge current situation and dig out new possibilities and ways to think and work. You could describe me as a jack of all trades but my main focus area and deep personal driver is Microsoft Teams since it has changed the way I work and did a giant step forward to make it possible to work from anywhere - the location does not matter even us much as it mattered before. Microsoft Teams opened the path for many organizations to rethink their practices, worklife, culture and start the change. That's why I am very passionate about Teams.

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.

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:

More articles

Leave a Reply

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

Latest articles