Logic Apps: How to add several actions inside a Logic App condition branch

In my last blog post, I talked about the new “The ability to call nested Logic Apps directly from Logic Apps Designer” and I mentioned that this great feature, not only allow us to create reusable pieces, but that will allow us to overcome some of the current Logic Apps limitations:

  • The ability to add more than one action inside the condition branch’s (this is actually a false statement);
  • or the ability to add more than one action inside the loop;

In this post we will address the first option, we will leave the second one for a dedicated post. Once again, in my previous post, we created a Logic App called “AddFileToDropbox” that:

  • Its trigger manually, which means through an HTTP post, allowing to be invoked by other Logic Apps
  • Then it will call an Azure Function to dynamically generate a filename;
  • Create a Dropbox file
    • The filename it’s provided by the Azure Function;
    • And the content of the message it’s passed in the HTTP request that triggers this Logic App.
  • And finally, return an HTTP response based on the status of the file creation

We will reuse this “child” Logic App in our demos here.

#1 Azure Monitoring Platform

Our “basic” demo scenario

The important thing here is to demonstrate the concept itself, not whether this is a real case or not, so, we will use connectors that are simple to test.

Let’s say that we want to listen to #LogicApps twitter hashtag, and:

  • If the tweet was made by someone other than me (@sandro_asp) then:
    • We need to call an Azure Function to dynamically generate a filename;
    • Create a Dropbox file
      • The filename it’s provided by the Azure Function;
      • And the content of the message will be the actual tweet text message.
  • If it’s a tweet made by me, let’s say I want to send it in an email to… my manager (just to annoy him)

Creating a Logic App with conditions inside

Let’s create a Logic App calling “ConditionsInsideLogicApp” (you can see the basic steps in my previous posts)

  • Add a “Twitter – When a new tweet appears” trigger, to look for a new tweet containing the hashtag “#LogicApps
Logic Apps Conditions Add Tweet Appear
  • Select the plus sign, and then choose “Add a condition
Logic Apps Conditions Add a condition

Note: if by any chance, you verify that the conditions branches, “if yes” and “if no, do nothing“, are not side-by-side as would be expected, but instead they are in sequence, one under the other:

Logic Apps Conditions note

do not be alarmed, there is nothing wrong with your editor. It just means that your monitor does not have enough resolution, you are using a large zoom or your browser window is too small to render the conditions side by side. If you switch for a different monitor or zoom out, you will see that they will be rendered side-by-side:

Logic Apps Conditions side by side
  • Now that we have the condition action we need to configure in the following manner:
    • In the “Object name” property we need to set the parameter “Tweet by” from the output of “When a new tweet appears” trigger
    • In the “Relationship” property we need to choose the option “is not equal to
    • And finally, on the “Value” property, we need to statically set the value “@sandro_asp
Logic Apps Conditions Tweet condition configuration

Note: If we look to our “If yes” branch we will see that we only have the ability to “Add an action” with means that we cannot create, at least for now, nested conditions (you probably can if you call another Logic App)

Logic Apps Conditions add action if branch
  • If we go to our “If yes” branch and “Add an action”
    • From the search box select “Show Azure Functions in my subscription” and select the Azure Function: “CreateFileName” and set the “Input payload object” as an empty JSON message:
{ }
Logic Apps Conditions add action if First action

Based on your user experience in the Logic App designer, you may think that you cannot add more actions inside the “If yes” branch because you don’t have the plus sign underneath the Call Azure Function action. Well, you are wrong!

#1 Azure Monitoring Platform

You actually can add several actions (conditions are not allowed) inside the same branch, by clicking once again the “Add an action” on the top right corner.

Logic Apps Conditions add action if second action
  • From the search box, type “Dropbox” and select the “Dropbox – Create file” action
    • Set the Folder path, let’s say the root by typing: /
    • Click on the Filename and set the parameter “Body” from the output of “CreateFileName” function as input
    • Switch to code view to edit Create file inputs to have the expected values
@{body('CreateFileName')['FileName']}
  • And then click on “File content” text box, and set the parameter “Text” from the output of “When an HTTP request is received” as input
Logic Apps Conditions add action if no email action

At the end your Logic App will have a condition with:

  • Two actions in the “If yes” branch
  • And one action in the “if no” branch
Logic Apps conditions

Save” your logic app and wait to a tweet to appear, we will see that a new file was added to your Dropbox or an email as sent to your manager

Second option

Because we already created a Logic App that makes the necessary steps for the condition “If yes“:

  • Generate a filename
  • And create a file in dropbox

We instead of having several actions, creating and repeating the same steps over and over again, we can call the “AddFileToDropbox” to do the same steps for us.

Logic Apps Conditions add action if call Logic App

Advantages of this approach:

  • We are reusing “code”
  • We can add “nested” conditions

Disadvantages:

  • We lose a little the run action history because we then have the action “AddFileToDropbox” but we cannot easily go to the child run and correlate the existing runs.
Logic Apps Conditions runs action history
Logic Apps Conditions runs action history

Explore more on: Tracking Message Properties

#1 Azure Monitoring Platform
Author: Sandro Pereira

Sandro Pereira lives in Portugal and works as a consultant at DevScope. In the past years, he has been working on implementing Integration scenarios both on-premises and cloud for various clients, each with different scenarios from a technical point of view, size, and criticality, using Microsoft Azure, Microsoft BizTalk Server and different technologies like AS2, EDI, RosettaNet, SAP, TIBCO etc. He is a regular blogger, international speaker, and technical reviewer of several BizTalk books all focused on Integration. He is also the author of the book “BizTalk Mapping Patterns & Best Practices”. He has been awarded MVP since 2011 for his contributions to the integration community.

Leave a Reply

Your email address will not be published. Required fields are marked *

turbo360

Back to Top