Tuesday, December 14, 2021

Create Approval Flow in Power Automate with Adaptive Card in MS Teams from MS Form response (Part 2)

Welcome back to the final part of the blog on how to Create Approval Flow in Power Automate with Adaptive Card in MS Teams from MS Form response (Part 1)

In the previous blog we submitted a form, and an approval request was created in Teams channel where the approve accepts or reject and then the result is recorded into an excel online sheet for usage. All these processes were made possible with Approval Flow in Power Automate.

 

In this final part, we will include a field for the responder to attach a file (Invoice or Proof) to the request being made.

Let’s get started. We will need to add the attachment field to the form we created.

 

Steps to do this:

  1. Open the form in editing state (this can be found in Forms application on the office portal)
  2. Click “Add new” under the “Give reason” field and click the drop-down arrow for more options.
  3. Next, click “File upload” and give the field a question or title (‘Upload invoice’) as shown below and you are done.

forms.png

 

Now, open the previous flow we created and now let’s edit the Excel Online sheet to include the “Upload invoice” field using the dynamic contents.

  • Invoice – “Upload invoice” (from the form field)

 

excelonline_invoice.png

 

Now, let’s save the flow and try submitting a request with an attachment to see the outcome. We are to get the attachment link in the excel online sheet.

 

Test results after approving the request with attachment

So many texts can be seen around the main attachment link.

This is not good!! 

Error link.png

 

 We need to do away with these texts around for the link to stand alone.

This can be done through the following steps:

 

Step 1:

Add an action right under the “Get response details” action. Type in the search “Data Operation” and select “Parse JSON” under the action tab.

  • Content – “Upload invoice” (this is the form upload field. Selecting from dynamic content)
  • Schema – "Copy and paste the JSON code below in here"

 

 

 

 

{
    "type": "array",
    "items": {
        "type": "object",
        "properties": {
            "name": {
                "type": "string"
            },
            "link": {
                "type": "string"
            },
            "id": {
                "type": "string"
            },
            "type": {},
            "size": {
                "type": "integer"
            },
            "referenceId": {
                "type": "string"
            },
            "driveId": {
                "type": "string"
            },
            "status": {
                "type": "integer"
            },
            "uploadSessionUrl": {}
        },
        "required": [
            "name",
            "link",
            "id",
            "type",
            "size",
            "referenceId",
            "driveId",
            "status",
            "uploadSessionUrl"
        ]
    }
}

 

 

 

As shown here:

JSON_upload.png

 

 

Step 2:

Add a new action next to the “Parse JSON” action. Type in the search “OneDrivefor business and select “Get file content using path” under the action tab. This will help us get the exact location for the attachment folder in OneDrive using the file path.

 

  • File Path: Apps/Microsoft Forms/Approval form/Question/ (path to my attachment)

 

At the end of the file path …../Question/ add the expression below:

 

 

 

first(body('Parse_JSON'))?['name']

 

 


Just as it is done in the image below.

filepath.png

 

 

Last step:

Let’s update the excel online sheet again with the expression below instead of connecting straight with the file upload field in the MS Form.

 

 

 

first(body('Parse_JSON'))?['link']

 

 

 

This will extract the exact link of the attachment from the previous file location and name.

 

Excelupdate1.png

 

Save the flow and run a test.

 

Results

Congratulation!! After same request has been made again. You realized the link is now visible and ready to be viewed compared to the previous we had.

 

See below:

Clean_Link.png

 

File opened when link was clicked.
FileOpenedBrowser.png

 

Summary:
We created an approval flow which is triggered by the submission of an MS Form. We move on to include the feature where the approval form should accept attachment but there is an issue where attachment from the form is not easy to access due to so many texts that are generated around the link. So, we went ahead to add JSON code and two function expressions to eliminate all unwanted texts to make the link stand alone. You can build upon this do more awesome projects under approval flow. 


Below, is an image the complete flow steps taken to make all these possible.

Final_flow.png

 

You can also download the flow package and import it into a new environment to work with.

Find attached the .zip file.

 

Resources to get you started and keep going!
Getting Started with Power Automate and Microsoft Learn

Official Power Automate website

Automate a business process using Power Automate
Free Microsoft 365 E5 instant sandbox

How to create Approval Flow in Power Automate with Adaptive Cards in MS Teams

Overview of Adaptive Cards for Microsoft Teams

Posted at https://sl.advdat.com/3q1zLLQ