November 17, 2024

The item function is oftentimes misunderstood since it’s not common to be used, but it’s beneficial. For example, when you’re inside a repeating action, like the Apply to Each action, you will need to use the elements of an object, like the Title in a SharePoint List Row. But what about if you’re using an array? There’s no object inside.

Let’s check how it works.

Usage

It doesn’t need any parameters to work. It only needs to be inside a repeating action.

To understand it better, let’s create an array using the createArray function.

createArray('Element1','Element2','Element3','Element4')

We have an array with 5 elements, so not let’s do an Apply to Each action to see the result.

Since it’s not an object, what should we put there? That’s where the item function comes into play. If you put, item() you’ll be able to access individual items for each new element of the array.

Here’s the function.

And here’s the result.

Let’s use a Get Item Action and fetch a bunch of items in a SharePoint list. If we use the same strategy above with the Apply to Each and the item function, we get the following:

As you can see, this may not be as useful to us, except if you’re doing some debugging (check “debug compose” below), so prefer to use the object reference instead of the item function.

Limitations

The item function is only useful when there’s an array of elements. If it’s an object, you may still use it, but it’s a lot more efficient to select the one you want to use in the list.

Recommendations:

Here are some things to keep in mind.

Debug compose

Once in a while, I like to use Compose action with elements to have a place where I can check the values. So, for example, I include, once in a while, Compose actions with references to objects like this:

It may look strange, but this is an excellent way to look at the “run history” and see the values before I do something with them. I call this a “debug compose”, and the item function can be used for this purpose. This way, you’ll have the array element or object and see the values in each position of the Apply to Each action, making debugging a lot simpler.

Only use it in arrays.

As shown above, you can get arrays from SharePoint’s Get Item Action, but that doesn’t mean that it’s helpful to us. You can then make the function more complex to get the value, but referring to the value is much more straightforward. Don’t complicate things that can be simple.

Sources:

Microsoft’s item Function Reference

Back to the Power Automate Function Reference.

Photo by Luke Porter on Unsplash

Manuel Gomes

I have 18 years of experience in automation, project management, and development. In addition to that, I have been writing for this website for over 3 years now, providing readers with valuable insights and information. I hope my expertise allows me to create compelling, informative content that resonates with the audience.

View all posts by Manuel Gomes →

Leave a Reply

Your email address will not be published. Required fields are marked *

Mastodon