Creating Your First Logic App

Note: This article assumes that you already have an active Azure subscription. If you do not have an Azure subscription, you can create one at https://azure.microsoft.com/.

Introduction

If you’ve used Microsoft Flow before, you’ll feel right at home working inside a Logic App. That said, while there are a lot of similarities (Flow itself is built on top of Logic Apps), there are still several core differences, and reasons why you might elect to use Azure Logic Apps over Microsoft Flow to implement no-code and low-code process automation.

While Flow is intended to be used by business users and offers a more self-service and user-specific workflow experience, Logic Apps are really designed for IT Pros. Logic Apps run as event and/or timer-based process within your Azure environment, meaning they’re not necessarily tied to a specific user. Logic Apps offer more advanced integration and lifecycle management capabilities, including the ability to leverage Azure Resource Management and source control.

For these reasons, you may choose to use a Logic App over Flow for scenarios that span across the organization, are scoped to a wider number of users, or have the mission criticality that justifies deeper testing, source control, and deployment techniques.

In this guide, we’ll create a basic Logic App that leverages ElasticOCR to OCR files added to OneDrive for Business. This guide is intended to show the mechanics of creating and rolling out your first Logic App. Error handling has been omitted for the sake of simplicity. If you don’t currently have an ElasticOCR subscription, you can sign up for 30-day free trial to follow along with this guide.

 

Creating a Logic App

To create the logic app, navigate to https://portal.azure.com and click the “Create a resource” button. Search for “Logic App”, select “Logic App” from the list, and click the “Create” button at the bottom of the information blade.

2.png

Start by entering a name for your Logic App. Your subscription will be pre-populated if you only have one, or you can select which subscription you want to align this Logic App with. Select whether you want to use an existing resource group or create a new one—if creating a new one, enter a name for the resource group. Lastly, select the location where you want to deploy this Logic App, choose whether you want to enable analytics, and click “Create”.

4.png

Once your Logic App has been provisioned, an in-browser notification will alert you and provide a link to navigate directly to your new Logic App. Alternatively, you can navigate to the Resource Group where your Logic App was provisioned and launch it from there.

5.png

Inside the Logic App blade, you’ll see the various tools for developing, configuring and monitoring your Logic App. Start by clicking on the “Logic App Designer” link under “Development Tools”.

6.png

The first thing you’ll see inside the designer is the ability to select from a number of canned templates. For the purposes of this guide, we’ll create a new Logic App from a blank slate. Scroll down and select the “Blank Logic App” tile from the templates list.

7.png

If you’re familiar with Microsoft Flow, at this point things will start to feel very familiar. The process for designing the Logic App using the Logic App Designer is identical to that of Microsoft Flow.

8.png

Like Microsoft Flow, all Logic Apps start with a trigger action. For this example we want the Logic App to execute when a new file is added to OneDrive for Business. Enter “OneDrive” in the “Search connectors and triggers” box, select “OneDrive for Business”, then select the “When a file is created” trigger.

10.png

If this is the first time you’ve used the OneDrive for Business connector, you’ll be prompted to create a new connection by clicking “Sign In”. This gives OneDrive for Business access to the account that you use to establish the connection.

11.png

With the connection established we can now specify the conditions and configuration for our trigger. Use the folder icon to navigate to and select the folder we want the Logic App to monitor (ie: “/Documents”), set “Infer Content Type” to “Yes”, and set the interval that you want the Logic App to check for new items.

13.png

Next, we want to add a condition that tells the Logic App to check the file type of any new file added to the folder. This ensures that we only send file types to ElasticOCR that the service can process, and will prevent failed runs of our Logic App if a user were to inadvertently add the wrong type of file to the folder.

Click the “New Step” button, then search for and select the “Condition” control.

15.png

Click the “Choose a value” field, and select the “File content type” property from the “When a file is created” action. Set the condition to “is equal to”, and enter “application/pdf” in the value field. Repeat this process for any/all file types you want to send to ElasticOCR. For this example, configure conditions for “application/pdf”, “image/jpeg”, “image/png”, “image/tiff” and “image/bmp” as those are the mine types for files ElasticOCR supports. Lastly, ensure the condition is set to “Or”.

16.png

Assuming the file meets one of the accepted file types, we now want to send the file to ElasticOCR. From this point on, everything we do will be inside the green “If true” side of the condition. Inside the “If true” side of the condition, click the “Add an action” button. Search for “ElasticOCR” and select the “Create a job with a file” action.

18.png

Much like when we created the OneDrive for Business connection, if this is the first time you’ve connected to ElasticOCR, you’ll be asked to create a connection by supplying your License ID, App ID, and entering a name for the connection.

20.png

Supply the filename of the file, by clicking on the Filename field, and selecting the “File name” property from the “When a file is created” OneDrive for Business action. Use the same process to set the “File Data” field to the “File content” property of the “When a file is created” action.

23.png

For the purposes of this guide, leave the Metadata field blank.

24.png

After Logic Apps sends the file to ElasticOCR, we want it to poll the ElasticOCR service to monitor for when the job becomes available for download. To do this, click the “Add an action” button then search for and add the “Until” control.

25.png

The “Until” control will perform the actions inside it until the defined condition is met. Until loops have configurable “Limits”, which determine the number of times the loop will run, as well as the duration it is allowed to run, until it terminates regardless of whether the condition has been met or not. In the case of polling our ElasticOCR job, we’ll assume that the loop needs to be able to run for 24 hours in order to support a Silver plan’s 24 hour SLA. To configure a 24 hour limit, we want to set the “Timeout” value to “PT24H”, and also set the “Count” to 290. The 290 is derived from our plan to check the job’s status every 5 minutes (24 hours times 60 minutes per hour, divided by a 5 minute polling interval, equals 288 executions).

27.png

Next we want to add the actions to the “Until” loop. Click the “Add an action” button inside the “Until” control. Search for, and add the Schedule “Delay” action, and configure it for 5 minutes. We perform the delay action first, to ensure that the Logic App will wait 5 minutes before checking the ElasticOCR job status the first time it enters the loop.

30.png

Immediately after the “Delay” action, click the “Add an action” button then search for and add the ElasticOCR “Retrieve a job” action. Click on the “Job Id” field, and select the “Job Id” property from the “Create a job with a file” action.

33.png

Now we’re ready to define the conditions of the “Until” control. At the top of the “Until” control, click the “Choose a value” box, and select the “Status” property from the “Retrieve a job” action. Note that you’ll see two ElasticOCR groups (“Create a job with a file” and “Retrieve a job”)—ensure that you use the “Retrieve a job” action for values from this point forward.

35.png

Set the condition to “is equal to”, and enter “Available” in the text box. This completes the “Until” control. When the loop is entered the Logic App will wait 5 minutes, check the status of the job, and compare the status to see if it equals “Available”. If the status is not “Available”, it will wait 5 minutes, check the status, and compare the status again. This process will continue until the job becomes “Available”, or the execution limits of the loop are met.

36.png

Once the job becomes “Available”, the Logic App needs to call ElasticOCR and download the completed file. To accomplish this, click the “Add an action” button directly after the “Until” control, then search for and add the ElasticOCR “Download a job” action.

38.png

The “Download a job” action has just a single property on it, the “Job Id” of the job we want to download. Click this field, then select the “Job Id” property from the “Retrieve a job” action.

40.png

We now want to update the original file in OneDrive for Business that started this whole process, with the version that ElasticOCR just completed processing. Click the “Add an action” button, then search for and add the OneDrive for Business “Update file” action. Set the “File” field to the “File identifier” property of the original “When a file is created” action, and the “File Content” field to the “File Content” property of the “Download a job” action.

44.png

Finally, once the original file has been updated, we need the Logic App to call ElasticOCR’s “Complete a job” action. Add this action, and set the “Job Id” to the “Job Id” property from the “Retrieve a job” action.

47.png

At this point, our Logic App is fundamentally done. Navigating to the “Overview” will show that our completed Logic App has 1 trigger defined, with 8 actions.

49.png

Add a file to the folder that the Logic App trigger is bound to, then click “Run Trigger” > “When_a_file_is_created” to execute the Logic App.

50.png

In the “Runs history” section, we now see that our Logic App is running. Clicking on the running instance of the Logic App allows us to view the status of each action in the Logic App. This is useful for debugging and testing your Logic App before rolling it out to your user base.

53.png

Once our Logic App completes successfully, the “Runs history” list should show a “Succeeded” status. At this point, your Logic App is live and ready to be used.


Refer to the Azure Logic Apps Documentation for more help getting started with Logic Apps, and be sure to take a look at ElasticOCR for all of your document OCR needs.