Introduction

Microsoft Integration Product team announced yesterday on their monthly webcast (that you can see it here) some of the new features that are now available in Logic Apps like:

  • “Run” any trigger now
  • HTTP Webhook in Designer
  • SQL Azure Connector now supports Store Procedures
  • Ternary Operator – @if()
  • “Workflow” function type
  • Manual Trigger Schema Support (jsonschema.net)
  • What’s In Progress in Azure Logic Apps?
  • Azure Functions Integration and a few other features
You can see more details about these features here: Azure Logic Apps Monthly Update – April 2016

At Build it was a new feature announced in Azure call “Azure Functions” which basic allows you to run small snippets of code out in the cloud. You can learn more about it here: https://azure.microsoft.com/en-us/services/functions/. This article will guide you in how can you start using Azure Functions inside your Logic Apps. 

Get started with Azure Functions

To get start using Azure Functions, currently in Preview, you can access to https://functions.azure.com/ and you just need to fill:

  • Your Azure Subscription from the drop box
  • Give a Name to the Function App
  • And select your desired Region
 
  • And then click “Create + Get started” button.

This will create your Function App and will redirect you to your azure portal subscription.


Let’s leave this windows open for now, because we will create our function through the Logic App design, and get to your Azure Portal subscription.

Create your Hello World Logic App

For this exercise we intend to create a very basic Logic App that will run once a day, notice that this is a simple Hello World, but instead of writing a static message "Hello world", we want to provide a more dynamic behavior and determining the day of the week that this Logic App is being executed and write “Hello World! this is #LogicApps and I hope you have a great [CURRENT_DAY]” (The day of the week: Friday, Saturday, Sunday, Monday, …)

For that we will call an Azure Function to get the day of the week and then post on your twitter this twitter post.

To accomplish that we need:
  • On the Azure Portal click on “Logic Apps” option and click “Add” to create a new Logic App.

    • If is not present you can find it by clicking “+ New” --> “Web + Mobile” --> “Logic App

Note: we will create everything from the scratch, including creating a: 

  1. Free App Service Plan: represents a set of features and capacity that you can share across multiple apps in Azure App Service, including Web Apps, Mobile Apps, Logic Apps or API Apps. These plans support different pricing tiers (Free, Shared, Basic, Standard and Premium) where each tier has its own capabilities and capacity.
  2. and Resource group: are logical containers that allow you to group individual resources such as virtual machines, storage accounts, websites and databases so they can be managed together.
  • In the “Create logic app” panel we need to give it:
    • A “Name”, for example “MyDynamicHelloWorldLApp”
    • And select the desired “Subscription” (if you have more than one)

    • Set a “Resource Group” or create a new one by selecting “+ New” option and give a resource group name in the “New resource group name” text field

    • And finally define the “App Service Plan” by choosing an existing plan or add a new one by
      • clicking “App Service Plan” --> “Create New” and then we need to:
      • set a “App Service Plan” name, for example “MyFreeLogicAppServicePlan”
      • select your desired "Location"

      • and then click “Price tier” --> “View All” --> “F1 Free

      • Click “Select” and in then “OK
    • Finally, on the “Create Logic app” panel click “Create” for the deployment process to start.
  • We have to wait a few seconds for the deployment process to finish, once finished we will be notified in the notification area.

  • If we refresh the Logic Apps page, we will now see and have access to the new Logic App we were building.

Note: if we click on “” you can pin this Logic App to your dashboard.

Create Logic App flow

To edit and create the logic flow of you Logic App, you just need to click on the Logic App name to open the Logic Apps Designer.

To accomplish the goal that we described in the beginning of this post we need to:
  • When your access to the Logic Apps Designer a search box is presented were you can search for available connectors or triggers (API) management by Microsoft (default option) or inside your subscription. From “Show Microsoft management APIs” option, click on the “Recurrence” trigger 

    • That will enable our Logic App to run periodically based on frequency and interval, in this case:
      • Frequency: “Day”
      • Interval: “1”

    • Note: Recurrence triggers do not have anything in the inputs object the common properties for all triggers are sufficient to define a basic recurring trigger.
  • Select the plus sign, and then choose “Add an action

  • When you select "Add an Action", again the search box will be presented were all the connectors with their available actions are listed. But now, on the search box you can select the option: “Show Azure Functions in my subscription

    • This will present all the Azure Functions that you can use inside your Logic App;
    • And also the availability to create new WebHook Node JS Functions
  • From the search box select “Show Azure Functions in my subscription” and then “Create New Function”.

  • On the “Configure Function Inputs”, and because with don’t have or need to send any input type an empty JSON message: “{}” and click “Next

  • On the “Function Authoring
    • Set the “Function name” as “GetHelloWorldTwitterMsg”
    • And past the following code in the “Code” text box
module.exports = function (context, data) {
         
    var d = new Date();
    var weekday = new Array(7);
    weekday[0]=  "Sunday";
    weekday[1] = "Monday";
    weekday[2] = "Tuesday";
    weekday[3] = "Wednesday";
    weekday[4] = "Thursday";
    weekday[5] = "Friday";
    weekday[6] = "Saturday";
 
    var n = weekday[d.getDay()];
         
  // Response of the function to be used later.
  context.res = {
    body: 'Hello World! this is #LogicApps and I hope you have a great ' + n
  };
                 
  context.done();
};

    • Click “Create
  • Once again, select the plus sign, and then choose “Add an action
  • From the search box, type “Twitter” and select the “Twitter – Post a new tweet” action

    •  The first step is to sign in to twitter and authorize Azure AppService Logic Apps to use your account
 

    • After you authorize the Logic App to use your account you can now configure the text to be posted in your twitter account
  • On “Post a new tweet”, click on “TWEET TEXT” text box and the outputs from the “GetHelloWorldTwitterMsg” function will be presented
    • Select “Body

  • Finally, you can select “Save”, on the Logic Apps Designer menu, to make your logic app live.

If you now check your twitter account, we will see a new tweet:

Manage, "Debug" and Test our Azure Functions

If you access to your Azure Function app page that we had accessed at the beginning of this post, and refresh it, you will see the new Function that we have created inside our Logic App

Here we are also able to manage, “debug” and test all the existing Azure Functions to check if everything is running according. And to create new ones.



References

This article was originally published at Logic Apps Hello World: Using Azure Functions inside Logic Apps. But please feel free to improve this article by adding new missing or important content, fixing spelling and so on.

See Also

Another important place to find a huge amount of Logic Apps related articles is the TechNet Wiki itself. The best entry point is Microsoft Azure App Service Resources on the TechNet Wiki.

Other languages