title | description | author | manager | editor | services | documentationcenter | ms.assetid | ms.service | ms.workload | ms.tgt_pltfrm | ms.devlang | ms.topic | ms.date | ms.author |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Add conditions and triggers to run workflows - Azure Logic Apps | Microsoft Docs |
Control how workflows run in Azure Logic Apps by adding conditional logic, triggers, actions, and parameters. |
stepsic-microsoft-com |
anneta |
logic-apps |
e4e24de4-049a-4b3a-a14c-3bf3163287a8 |
logic-apps |
integration |
na |
na |
article |
01/28/2017 |
stepsic |
In the previous topic, you created your first logic app. Now we will show you how to build a more complete process using App Services Logic Apps. This topic introduces the following new Logic Apps concepts:
- Conditional logic, which executes an action only when a certain condition is met.
- Code view to edit an existing logic app.
- Options for starting a workflow.
Before you complete this topic, you should complete the steps in Create a new logic app. In the Azure portal, browse to your logic app and click Triggers and Actions in the summary to edit the logic app definition.
You may find the following documents useful:
- Management and runtime REST APIs - including how to invoke Logic apps directly
- Language reference - a comprehensive list of all supported functions/expressions
- Trigger and action types - the different types of actions and the inputs they take
- Overview of App Service - description of what components to choose when to build a solution
Although the original flow works, there are some areas that could be improved.
This logic app may result in you getting a lot of emails. The following steps add logic to make sure that you only receive an email when the tweet comes from someone with a certain number of followers.
-
Click the plus and find the action Get User for Twitter.
-
Pass in the Tweeted by field from the trigger to get the information about the Twitter user.
-
Click the plus again, but this time select Add Condition
-
In the first box, click the ... underneath Get User to find the Followers count field.
-
In the dropdown, select Greater than
-
In the second box type the number of followers you want users to have.
-
Finally, drag-and-drop the email box into the If Yes box. This will mean you'll only get emails when the follower count is met.
The forEach loop specifies an array to repeat an action over. If it is not an array the flow fails. As an example, if you have action1 that outputs an array of messages, and you want to send each message, you can include this forEach statement in the properties of your action: forEach : "@action('action1').outputs.messages"
In addition to the designer, you can directly edit the code that defines a logic app, as follows.
-
Click on the Code view button in the command bar.
This opens a full editor that shows the definition you just edited.
By using the text editor, you can copy and paste any number of actions within the same logic app or between logic apps. You can also easily add or remove entire sections from the definition, and you can also share definitions with others.
-
After you make your changes in code view, simply click Save.
There are some capabilities of Logic Apps that can only be used in the code view. One example of these is parameters. Parameters make it easy to re-use values throughout your logic app. For example, if you have an email address that you want use in several actions, you should define it as a parameter.
The following updates your existing logic app to use parameters for the query term.
-
In the code view, locate the
parameters : {}
object and insert the following topic object:"topic" : { "type" : "string", "defaultValue" : "MicrosoftAzure" }
-
Scroll to the
twitterconnector
action, locate the query value, and replace it with#@{parameters('topic')}
. You could also use the concat function to join together two or more strings, for example:@concat('#',parameters('topic'))
is identical to the above.
Parameters are a good way to pull out values that you are likely to change a lot. They are especially useful when you need to override parameters in different environments. For more information on how to override parameters based on environment, see our REST API documentation.
Now, when you click Save, every hour you get any new tweets that have more than 5 retweets delivered to a folder called tweets in your Dropbox.
To learn more about Logic App definitions, see author Logic App definitions.
There are several different options for starting the workflow defined in you logic app. A workflow can always be started on-demand in the Azure portal.
A recurrence trigger runs at an interval that you specify. When the trigger has conditional logic, the trigger determines whether or not the workflow needs to run. A trigger indicates it should run by returning a 200
status code. When it does not need to run, it returns a 202
status code.
Services can call a logic app endpoint to start a workflow. See Logic apps as callable endpoints for more information. To start that kind of logic app on-demand, click the Run now button on the command bar.