Imran
Azure, Cloud, Serverless

Azure Logic Apps – Approval Workflow using HTML Form

Recently customer approached me to build “Microsoft Teams” approval workflow. Their IT support was overwhelmed with requests to create new Microsoft Teams and decided to automate the process. Here’s the breakdown of requirements

I decided to build workflow using Azure Logic Apps and Azure Function. While most part is simple to automate, the challenge was to create an HTML form that could be served via Logic Apps.

Please note: Since the purpose of this blog is to show how HTML forms can be served via Logic Apps, I will only be discussing the high level approach and will not go into details of other parts.

Microsoft Forms

First of all I decided to use Microsoft Forms to collect user input.

Example User input Microsoft Forms
https://forms.office.com/

Azure Logic Apps

Azure Logic Apps is a great way to automate business workflows. You get 100s of connectors to integrate with external services and services within Azure. Taking user input on Microsoft Forms and kicking Logic Apps workflow was simple but creating custom HTML form served via logic app where Admins could approve/reject or override the request was a challenge. Here’s what I did to achieve this. I created 2 Logic Apps to complete this workflow. Lets call them Logic App “A” & “B”.

Logic App A

Logic App A is triggered as soon as user submits Microsoft Form as you can see below. You can consider this main workflow.

This workflow has important task to trigger Logic App B (discussed below) using webhook action. This workflow will pass following parameters to Logic App B.

When Logic App A is triggered this workflow stops at webhook action and awaits until Logic App B will callback.

Logic App B

Logic App B is Http triggered and is used to accomplish 2 tasks (only one at a time)

Logic App B receives parameters (“formid” , “sendemail” and “url”) and save them into variables. Callback url is very important and represents the webhook action from Logic App A.

Since query string parameter “sendemail=yes” (as mentioned above),this workflow notify Admin that new request is submitted and Logic App B workflow completes.

Email Received by Admin
Constructing Hyperlink “Click here to approve or reject”

If you notice in image above there is hyper link in Email “Click here to approve or reject”. Clicking this link will drop admin on HTML page. This HTML page is served by Logic App B. Basically clicking the hyperlink runs the workflow again but this time “SendEmail=no” so no email is sent , and workflow only displays the HTML form as shown below. This form will display answers from user who originally submitted the request.

Admin can approve/reject or override the request

Construct HTML form in Logic App B

Serving the HTML form via Logic App is the meat of this whole workflow. At the very last step on Logic App B I have HTTP response action that contains HTML form. Whenever Logic App B is triggered via email link (or simply copy pasting HTTP url of this logic app in browser) this form is served to the browser.

I copied the HTML in Notepad and you can see this is a standard HTML form. If you remember in the query string parameters we received “formId” from Logic App A, I used this “formId” in earlier steps to extract user answers (from Microsoft Forms) and filled the variables . In the last step I am using same variables to display user input for admin to view (highlighted below)

In the same HTML page I am using jQuery to validate HTML input fields and using Ajax to submit the request. Now you would be wondering where do we submit this request ? If you remember we received webhook url (callback) from Logic App A in the query string parameters, it’s the same callback url that I am using in ajax request.

As soon as the admin approve/reject the form , the form is submitted to webhook action in Logic App A which is still in awaiting state. Logic App A will continue with the data it received via form and will do either one of the following :

Below are some of the images from Logic App A when it continues after receiving Form data from Logic App B.

Logic App A webhook continues after receiving data from Logic App B Form
If Approved Teams Instance is created

Like the post ? Share !

Related posts

Modern Web Apps Architecture with AWS Fargate

Imran
August 20, 2019

Introduction to Microsoft Azure Bot Service

Imran
July 15, 2018

Microservices and Azure

Imran
March 16, 2019
Exit mobile version