Thursday, February 9, 2017

Building a String in an Azure Logic App

In an Azure Logic App, one way to build a string containing multiple values (for example, within a "For Each" loop) is to use an Azure Storage Blob. First, add an action that creates a blob. Then, in your For Each block, use a "Get blob content using path" action along with an "Update blob" action.

To make this work in a loop, though, you'll need to add the following property and value to the For Each block definition in the underlying Logic App code:

"operationOptions": "Sequential"

Example:

"forEach_email": {
       "type": "foreach",
       "foreach": "@body('email_filter')",
       "operationOptions": "Sequential",
       "..."
}

Without that setting, the blob you're building will very likely be incomplete. That's because Logic Apps run loops in parallel. So, by the time the app has retrieved the current blob contents and has appended the next value, another thread of the app has done the same thing and the result will be an unpredictable set of data.

The following For Each block from a Logic App demonstrates this technique.



Note that it's certainly possible that I missed a feature in Logic Apps that helps to build a string, such as some sort of "Append to a String Variable" action, which will make my use of a blob for this look silly. If I did miss this, please leave a comment to set me straight. Otherwise, Logic Apps team: We need an "Append to a String Variable" action.   :)

No comments:

Post a Comment