Arrays are part of the building blocks of Power Automate. We can get arrays from many actions like the SharePoint “Get Items” action, for example. But there are a lot of times that we only want the first element of the array. So that’s where the Power Automate “first “function comes into play.

Let’s see how to use it efficiently.

Usage

It follows a simple pattern.

  1. Array to parse

Let’s start with a simple example:

createArray('Manuel','T','Gomes')
first(<array>)

will return 

'Manuel'

How about if the array is empty.

createArray()
first(<array>)

You’ll get an error message as follows:

Unable to process template language expressions in action 'Compose' inputs at line '1' and column '6310': 'The template language function 'createArray' expects a comma separated list of parameters. The function was invoked with no parameters. Please see https://aka.ms/logicexpressions#createArray for usage details.'.

You always need to check if the source array is not empty. If you don’t check, your Flow will fail. Here’s a skeleton on how to do it.

I recommend using the null and length function so that you’re sure that the data is valid.

We’re using the createArray function to generate a test array, but you’ll probably use another action in your case.

Finally, let’s check if it’s a string. We can do the following:

first('Manuel,T,Gomes')

will return

'M'

Here you can consider the string as an array of characters. The Power Automate “first “function will return the first character of the array. The same happens if there are spaces in a string.

first('Manuel T Gomes')

will return

'M"

Please don’t use this to break comma-separated strings. The split function is better at doing this. You can also check my “How to parse a CSV file” article and template for more details.

Limitations

I could not find any limitations for this function, but please let me know if you do.

Recommendations:

Here are some things to keep in mind.

Always check the array.

In my opinion, the “first” function would be a lot more valuable if it returned an empty array when the source array was empty instead of an error. By returning an error, we need to validate if the array is not empty; otherwise, the Flow will fail.

It’s not a big deal, but be sure to validate the data to avoid having failing Flows.

Don’t nest

There’s no real reason to do it, but if you find yourself in a situation where you have nested first functions in a formula, you should review it and make everything more straightforward.

Sources:

Microsoft’s first Function Reference

Back to the Power Automate Function Reference.

Photo by Possessed Photography on Unsplash

Manuel Gomes

I'm a Project Manager with experience in large projects and companies. I've worked in the past for companies like Bayer, Sybase (now SAP) and I'm currently working for Pestana Hotel Group.

View all posts by Manuel Gomes →

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: