· Puttarak Khwan · Tools · Automation · Microsoft  · 4 min read

Introduce the sample usage of Microsoft's Power Automate with SQL Server

A comprehensive introduction to the capabilities, benefits, and limitations of Microsoft's Power Automate.

A comprehensive introduction to the capabilities, benefits, and limitations of Microsoft's Power Automate.

Hello everyone! I’ve been away for a long time from blogging due to various events that have kept me busy, making it challenging to find time for writing. In my latest article, I briefly introduced Power Automate. Today, I’d like to try creating a simple Flow so that everyone can see how it can be practically used.

Prerequisites

  • You should have an account with a subscription that allows you to use the Power Automate service, such as Microsoft O365 E1, E3, E5 subscriptions, and similar.
  • In case you don’t have a subscription, the minimum cost for using Microsoft Power Automate is $15 per user (subscription) or $0.6 per flow run (pay as you go).
  • You should have a SQL Server in the cloud for testing purposes.

Objective: We are going to create a Flow that will send a Leave Approval Email only when new data is added to the table in SQL Server.

  1. First, let’s create a table to use on SQL Server:
CREATE TABLE Example_Leaves
(
  LeaveID INT NOT NULL IDENTITY PRIMARY KEY,
  Requestor NVARCHAR(100) NOT NULL,
  RequestDate DATE NOT NULL,
  SubmittedDate DATETIME NOT NULL,
  LeaveDetails NVARCHAR(MAX),
  IsApproved BIT NOT NULL DEFAULT 0
);

Note: In this example, the Requestor field will store the requestor”s email.

  1. Next, go to https://make.powerautomate.com/ and click on “Create” in the left panel.

  2. Choose “Automated cloud flow” and select “When an item is created (V2) SQL Server” as the trigger.

    • Once the “Example Leave Request” flow is created, enter the connection details for your SQL Server and click “Create connection.”
    • After the SQL Server connection is created, you will see the Server name, Database name, and Table name. Create Power Automated Flow
  3. Once the “Example Leave Request” flow is created, enter the connection details for your SQL Server and click “Create connection.” Create SQL Connection in Flow

    After the SQL Server connection is created, you will see the Server name, Database name, and Table name. Choose SQL Connection in Flow

  4. Click the ”+ New Step” button and select “Start and wait for an approval.” Fill in the Approval type, Title, Assigned To, and Requestor, as shown in the example below.

    Note: In this case, I selected “Approve/Reject — First to respond” as the Approval type, which means anyone can approve/reject the request in the Assigned To field.

    Create the approval process in Flow

  5. Click the ”+ New Step” button and select “Condition.” Then, select the Outcome in the “Choose a value” field to compare it with “Approve.” Check condition outcome process in Flow

  6. In the “If yes” section, choose “Update row (V2)” for SQL Server to update the row and set the IsApproved field to true. Update row in SQL Server

    Note: Do the same in the “If no” section, but set IsApproved = false.

  7. After the “Update row (V2)” action, select “Send an email (V2)” from Office 365 Email to send an email confirming the approval details to the Requestor. Send an update notification service

  8. Done! 🥳 Overall of workflow processes

Once you’ve created the Flow, let’s trigger it to see how it works.

  1. Insert some data directly into the SQL Server table:
INSERT INTO [dbo].[Example_Leaves] (Requestor, RequestDate, SubmittedDate, LeaveDetails)
VALUES ('{your-email}', '{your-request-date}', GETDATE(), '{your-request-detail}');

Select row in table on SQL Server

  1. After inserting data into the table, let’s check the Flow to see if it starts running. In the image below, we can see that there is one flow with Status = Running. Note:

    • The Flow may take a short delay before triggering.
    • Status = Running until the Approver approves/rejects the request. Power Automated workflow details
  2. Now, let’s check our Inbox to see if we received the Approval email. The Approval Email will look like the image below, allowing you to Approve/Reject the request. Approval an email and success notification

  3. Let’s check if the IsApproved value in the table changes after we click “Approved” in the email and if the approval confirmation email is sent back to the Requestor. Ta-daaa! It works perfectly! 😄 Approved an email and update row

That’s it! For anyone interested in using Power Automate for simple applications, I hope this will be helpful. But before you use it, please study both the advantages and disadvantages of Power Automate. See you next time! 👋


P.S. Lastly, if anyone is interested in reading more about the technology of Mycos Company, you can follow and read further content on their Medium page at https://medium.com/mycostech


Mycos is a software consulting company in Chiang Mai, Thailand specializing in all things Microsoft

Share:

Related Posts

View All Posts »