Arrays / Looping structure – Logic Apps

Arrays / Looping structure - Logic Apps

This post covers what’s necessary to iterate over a collection of data when building workflows on schema version 2015-08-01-preview. This version differs from schema 2014-12-02-preview, which can be found here. If you are still looking for the “Repeat over a list” menu item, keep on reading.

Arrays / Looping structure – What’s new

Within the release of version 2015-08-01-preview, a lot has changed when it comes to iterating over a collection data. The most noticeable thing is that the designer doesn’t include the “Repeat over a list” option. Next to this, the Workflow Definition Language has been altered to address some naming issues. Renaming Repeat to Foreach and RepeatItem to Item. In addition, the functions @repeatItem(), @repeatBody() and @repeatOutputs() have been removed.

Smart(er) designer

At this point, you might ask yourself how to iterate over items when creating a Logic App workflow using the designer. Well, in most cases, the new designer is smart enough to determine this on its own, just by looking at the swagger metadata exposed by the action responsible for gathering the data. Surprisingly, this works perfectly for complex types like a collection of JSON objects like the example below:

The designer understands what properties are available and will create the looping structure automatically.

Arrays-Looping-structure

List of simple types

When it comes to simple types like a JSON array of strings, booleans, integers, etc., some additional work is required. By default, the designer indicates that there is a body. However, it won’t create the for each structure.

To fix this, open the workflow in edit mode and move over to code view. Here you add "foreach": "@body('GetArrayOfStringsJson')". And make sure the body is set to @{item()} and not @item. The complete sample looks something like this; (depending on what action type you are using to consume the data)

Documentation: https://msdn.microsoft.com/en-us/library/azure/mt643789.aspx

Post Navigation