I needed to check if an HTML table had data or not. Usually when I need to check I have two expressions I go to first.
I tried using empty() and found that the HTML table even when empty, is not truly empty.
I then tried length() and found that when the HTML table is empty there is still a length of 30.
I have some data that is used to track different devices that can be loaned out. The data has properties like, Type of device, Serial Number, Etc.
The data comes in, and looks like this:
"device": "iPhone 11 Pro",
"device": "Samsung Galaxy S20",
"device": "Apple Watch Series 5",
"device": "Surface Pro X",
I want to put this array of data inside a HTML table and send it out on an email. The problem is, my data might be empty, as only available devices will show up in my data.
I need to check if the HTML table is empty, if it is empty:
Send email with HTML table
Send email without HTML table
For this Flow, I will be using an Array Variable to simulate my data coming in from another system.
I will call this Variable ‘Data‘.
The HTML table action will be added underneath.
You will need to determine if you want to use ‘Custom columns‘ or ‘Automatic columns‘ This can be done in the advanced options in the HTML action:
My ‘Data‘ Variable is empty at the moment. This is what we want for our first run, we want to get the length of the HTML table when its empty.
Next add a ‘Compose‘ action, and use the expression length(), pass in the HTML table as the parameter. For example, my expression looks like:
Now run the Flow with no Data in the HTML table, and check your Compose action to see what the length is. In my case it is 30
Now we can add a If Condition to check if the length is greater than 30
** TIP **
I am passing in the Compose action into the condition, this allows me to see what the outputs of the Compose action before it gets evaluated inside the condition. This is extremely useful for troubleshooting
The Flow will go into the ‘If yes’ block if the HTML table has data
The Flow will go into the ‘If no’ block if the HTML table is empty
Of course checking the Data Variable itself for length could work way better. This example is mainly for data that can come in that could have loads of junk. For example:
An HTTP API could bring in no data, but still have other information attached like, headers, status code, version. In this case we can only do conditional checks on the HTML table, since our Data variable will always have something being passed in.
I used this method to help someone on the Community Forum, check it out here: