Using variables in Logic Apps

published in category technology on Aug 16, 2017

Azure Logic Apps team has been really busy during the last few months and it seems that they keep rolling out new features with amazing pace. As I ’m working my way through all the new shiny bits and pieces myself, I try to write short introductions about the features. First up is variables.

You would expect to have ability to use variables with any modern programming language (and integration platform). Logic Apps team introduced first version variables few months ago, but the feature set was rather limited. You had only integer or float type of variables and after initialization you could just increment the values.

During summer we have seen another iteration of the functionality with bit more capabilities. There are new variable types: boolean, string, object and array. In addition to incresing variable value, there is now action to decrease variable value. It is also possible to set variable value after initialization. You can use expressions when setting the value, but it is still not possible to refer to the existing value of the variable. For example it is not possible to concatenate a string to the current value of string type variable.

So how do you get started? By initializing some variables:

As you can see, it is possible to give initial value of the variable as you would expect. It is also possible to use value from an existing object as the initial value of a variable. Here I have used a parameter called counter from the request that triggers my logic app.

Setting the value of a variable later on in the process can be done with set variable action:

In this case, I concatenate a string parameter from the initial request (variableContent) and concatenate sting ‘_added’ to it.

My original idea was to just concatenate a string value to the initial value of my variable, but as I mentioned it is not supported:

Manipulating integer variable values is really straight forward. You can use set variable as in the previous example or use special actions to increase or decrease the value. You just define the variable and the size of the increment:

Initializing array-type variable is as easy as with any other type:

However, I’m not aware of any easy methods that you could use to manipulate the array after setting it’s initial value (adding new items to the array or removing unwanted ones).

You can refer to variable value with notation variables(‘name_of_my_variable’). For example you could make evaluation against variable value in decide action:

Couple of things that you should be aware of about variables in Logic Apps:

  • variables are global within an instance of Logic App execution. You can use the variable at any stage of your process after initialization.
  • if you have paraller actions within your workflow (for example loop that you haven’t set to be executed in sequential mode), it is not wise to manipulate variable values. As the variables are shared between the parallel actions, you might end up with a rather unexpected result.

Support for variables in Logic Apps is still a young feature and it can be seen in the rather limited feature set. However, you can currently already implement simple use cases with variables and I’m sure we will see more capabilities added in the upcoming releases. Once manipulating variable values becomes more flexible, I thing variables become very usefull tool when designing Logic Apps.

My name is Juha Ryhänen. I’m interested in everything related to productivity, remote work, automation and cool gadgets. This is my personal website where I write about the things I find interesting. Maybe you do too? [More]

+358 50 543 4543 | [email protected] | Twitter