Using Azure Storage Account Table as Config Store for Logic Apps | How to read and write from Logic App to Azure Storage Account Table

{tocify} $title={Table of Contents}


I stumbled upon a scenario where I had to decide whether a section of actions in Logic app workflow is to be executed or not based on a flag.

If Flag is True, then execute those actions else no.

Using IF Else is what is to be done, but the value(flag) to be checked is not part of data coming in. 

It has to be stored somewhere which needs to be referred at runtime, as the flag value would be changed by Business Team as per their need.

Now the question was where to store it?

Options are in config file stored as blob, in a SQL Table but both of it doesn't look optimal.

So went ahead with another option - Azure Storage account Table.

What is Azure Table Storage 

It is a sub-service of Azure Storage account service.

Azure Table storage is a service that stores structured NoSQL data in cloud, providing a key/attribute store with a schema less design and no relationships.

It is a collection of rows(entity). And each entity can have up to 255 properties (columns and values) out of which following property are default- Partition key, Row key and Timestamp.

Partition key and Row key are used for Indexing.

Let's see now, how to create Table in storage account, adding an entity in it then how to read the entity from Logic App and how to create/update an entity in Table using Logic app.

Create a Table in Storage account

On Azure portal search for Storage account, create one storage account

In the storage account, go to Data Storage section, select Tables and click on +Table

Provide the name and click OK.

Create a Table in Storage account

After the table is created, let's add an entity in it.

Click on Storage Browser from left Pane -> Select Tables -> ConfigTable -> +Add entity

Add entity in Storage Table

Provide the values against PartitionKey and RowKey.

Click on Add Property button and add the key and its value as shown in above image.

And below is how it looks - Azure Table storage with an entity

Azure Table storage with an entity

Now, let's see how to read an entity in Logic App

Create a Logic app

Create Logic App to read Storageaccount table

Just for the sake of demo, creating a Recurrence trigger-based logic app

1. Add a Recurrence Trigger
2. Add new step, Search for Table and from the list select Get Entity or Get Entity(v2)

Selecting Get entity Action in Logic App

As this is first time we are connecting to it, following will be presented to create a Connection first

Api connection to Storage Account

Provide Connection name, Select Authentication Type as Access Key (other options are Azure AD Integrated and Logic Apps Managed Identity)

Next provide the name of Storage account (which you created above) 

To get the access key, go to storage account -> Security + networking -> Access keys and copy either key1 or key2
storageaccount key

Provide this Access Key against Shared Storage Key 

Configure Get entity action in logic app

Now Provide the Table, Partition Key and Row key

capturing value returned from Table Storage

To see and use the ProcessFlag value, let's add a variable and assign it to the output of above action.

Against value provide :            body('Get_entity_(V2)')?['ProcessFlag']

That's all we need to do to get value from Table storage.

Testing - Read an entity from Table

Manually triggered the logic App, checked the Run history

Testing output

As can be seen above True is the value set for the variable. 

And it is set using the value which is returned from above action (Get entity (V2)), lets see what is output of it to get more clarity

Output of Get entity action

We saw, how to read an entity from Table Storage, now let's see how to update.

Suppose, after finishing the above steps in Logic App, we want to log the current timestamp to denote when the last processing was done.

To achieve this we can add another entity in the table to hold this value. 

We have two options to go with
1. Go to Table Storage and create an entity and update that using Logic App
2. Create and Update an entity in Logic App using single Action (Insert or Replace entity action in Logic App)

Let's see the second option, in the logic app add another action - from Azure Table Storage select Insert or Replace Entity (V2) action 
Insert or replace entity action in Logic App

As we have already created a connection to same Table storage is used, however if needed it can be changed.


Select the Storage account name and Table from dropdown, provide value against Partition Key and Row Key.

And against Entity provide following: 
  "LastRunDateTime": "utcnow()"  }

That's it. Above action will create entity if it does not exist, if exist it will simply replace it

Testing - Update an entity in Table

To test, manually triggered the logic app and checked the Run history

Logic App run history

As can be seen value was assigned to LastRunDateTime, to validate let's check in ConfigTable in Table Storage

entity inserted in table storage

So a row gets added in the table implicitly by logic app (It created), now again I manually triggered the logic app to test the Update functionality
updated entity in table using logic app

And yes the entity was updated(replaced) with new value as expected.

Learn More about Logic App

Post a Comment

If you have any suggestions or questions or want to share something then please drop a comment

Previous Post Next Post