Flow controls, SplitOn, and scope in Logic Apps

Integration solutions are complex to build where we need to communicate with multiple systems and devices and follow different design patterns based on application requirement. When we develop integration solution, we are not confined to the same architecture design, but we use combination of multiples patterns for our solutions.

For each loop

In Logic Apps, you can use the add a For each action to iterate over an array item and perform the action or set of actions on each item.

To demonstrate the use case of the add a For each action, here is a simple Logic App that gets a list of new products from HTTP request and Logic App iterate through individual product in the array and send a notification mail to inventory.

For each loop

We have used a single trigger and an action that is send the email. You can have multiple actions associated with your add a For each action, which can perform a necessary action based on your workflow design. To get deep understanding, we would advise to look at the code behind the file of Logic App workflow.

For each loop

A foreachaction can iterate up to 5000 rows, and each of the iteration will be executed in parallel to the running instances.

Note

You can run the foreach action in Logic Apps as single threaded by using operationsOptions within the Logic Apps workflow.

For each loop

The Do Until loop

This indicates looping until a condition is met. Once you add Do Until within your Logic app designer, you need to define the entry and exit conditions.

Exit criteria includes the following:

  • Time
  • Count of iterations

The Do Until loop

To demonstrate the use case with Do Until, here is a Logic App that will be triggered from an HTTP endpoint; once the request is received through trigger, Logic App posts the request message to another external endpoint and checks for the HTTP status code - success or failure. In case of failure, Logic App retries to service call.

This logic App will complete its processing or exit the loop if any of the following conditions are met:

  • HTTP status code is 200
  • Loop until 60
  • Timeout 1 hour

Exit conditions mentioned earlier are default values. You can modify timeout and retry count properties directly from Logic Apps code behind file.

The Do Until loop

Similar to the for each loop, you can have multiple actions associated with the Do Until loop. You can also associate variety of conditional expression within the Do Until loop.

SplitOn

Let's say you have a trigger in your Logic App that receives an array items. Now you want to debatch array items and start a new workflow per item. You can accomplish that using SplitOn. This is very useful when you want to poll an endpoint that can have multiple new items between polling intervals.

For example, consider the following message you receive in your Logic App workflow. Now here I may only need the item detail to pass to my database table or to other API for further processing.

{ 
  "Status": "success", 
  "Items": [ 
    { 
      "id": 1, 
      "item": "book" 
    }, 
    { 
      "id": 2, 
      "item": "pen" 
    } 
  ] 
} 

You can use the following SplitOn command in the workflow definition:

"splitOn": "@triggerBody()?.Items"

SplitOn

This will return each item detail as shown here and can be used to start a new event or other next action:

{"id":1,"name":"book"} 
{"id":2,"name":"pen"}  

SplitOn

Currently, SplitOn arrays are limited to 1000 items.

Switch statement

While creating workflow for your enterprise you are often required to take different actions based on the content of the message. For example in case of polling your outlook for new messages you might need to take different actions based on the subject of the email. 

Switch statement

Single run instance

There will be multiple instances where you want to process the incoming request in sequential basis. In Logic Apps sequential workflow can be easily done by using operationOptions to singleInstance on the trigger definition.

"triggers": {
    "mytrigger": {
        "type": "http",
        "inputs": { ... },
        "recurrence": { ... },
        "operationOptions": "singleInstance"
    }
}

Scope

Scope is defined as grouping of executable actions within the Logic App. The group of actions include workflow actions and exception handling. You can use a Logic App designer to add a scope and its associated actions.

Scope

Here, we have a Logic App that is being invoked by manual http trigger. In scope, we have two actions - one is to post every request to the HTTP endpoint and other if an amount is greater than a fixed value, then send a mail for the workflow approval.

Scope

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset