cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Mike2500
Level 8

Get access to single element of array outside of loop

I need to send an approval email using data that is retrieved from a SharePoint Get Items action. The Get Items action is configured with a "maximum get count" of one, but of course that one item is still in an array. Since I can't send an approval email inside of a for each, I need to somehow get access to that one element outside the array. 

 

 

As an alternative, I need to query a sharepoint list for a single list item. "Get item" only allows to get items by Id, which I won't have. "Get Items" works fine, except that it return the single item I need in an array.

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support Team
Community Support Team

Re: Get access to single element of array outside of loop

Hi @Mike2500,

 

Yes, we could take use of Compose Action to get the array elements.

And there are two ways in your situation.

First option:

(Assume the field that you would like to show is the Title field)

Add a compose Action, in the input box, copy and paste the following:

"@first(body('Get_items')?['Value'])?['Title']"

The first() function would get the first item of the Array, then using ?['Field'] to find the proper elements.

 

 

Second option:

Also add the Compose Action, and in the Input Box, copy and paste the following:

"@body('Get_items')?['Value']?[0]?['Title']"

Writing in this way would be able to find the other array item, in Microsoft Flow, the formula language is Windows Definition Language, and this language uses number to query the array item, start from 0.

So here the formula would also return the result as the previous one.

See screenshots:

5.PNG6.PNG

 

Workflow Definition Language reference:

https://docs.microsoft.com/en-us/azure/logic-apps/logic-apps-workflow-definition-language

If you need any further help on this, please post back.

Regards,

Michael

 

Community Support Team _ Michael Shao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
Community Support Team
Community Support Team

Re: Get access to single element of array outside of loop

Hi @Mike2500,

 

Yes, we could take use of Compose Action to get the array elements.

And there are two ways in your situation.

First option:

(Assume the field that you would like to show is the Title field)

Add a compose Action, in the input box, copy and paste the following:

"@first(body('Get_items')?['Value'])?['Title']"

The first() function would get the first item of the Array, then using ?['Field'] to find the proper elements.

 

 

Second option:

Also add the Compose Action, and in the Input Box, copy and paste the following:

"@body('Get_items')?['Value']?[0]?['Title']"

Writing in this way would be able to find the other array item, in Microsoft Flow, the formula language is Windows Definition Language, and this language uses number to query the array item, start from 0.

So here the formula would also return the result as the previous one.

See screenshots:

5.PNG6.PNG

 

Workflow Definition Language reference:

https://docs.microsoft.com/en-us/azure/logic-apps/logic-apps-workflow-definition-language

If you need any further help on this, please post back.

Regards,

Michael

 

Community Support Team _ Michael Shao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

FenderBerg
Level: Power Up

Re: Get access to single element of array outside of loop

Hi,

 

Thanx for this answer, this helps me a lot. The field i want to get out of the compose action is the email address of a sharepoint person field. When i point to this field i get something like this:

 

{
"@odata.type": "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
"Claims": "i:0#.f|membership|bla@bla",
"DisplayName": "bla",
"Email": "bla@bla.nl",
"Picture": "",
"Department": "IT",
"JobTitle": "Consultant"
}

 

so i used the compose action to get this: 

first(body('get_items')?['Value'])?['person']
 
but how do i get just the email address?
Mike2500
Level 8

Re: Get access to single element of array outside of loop

The action you're looking for is Parse JSON. Add the action, and click the button that says: "use sample payload to generate schema", and in the dialog that appears, paste in the exact string you put above, including the { }. In any action after the Parse JSON action, you should have access to any of the data points, including email.

amdass
Level: Power Up

Re: Get access to single element of array outside of loop

I am getting items from a Sharepoint list and using the flow expression "formatDateTime(body('Get_items')?['value']?[0]?['Deployed_Date'],'MM/dd/yy')" which works fine but instead of hardcoding the array integer value to 0, I need to make this dynamic based on

current array value. This is because after I do a 'get items' from Sharepoint, I have an 'Create HTML table', and need to format the current deployed_date. Any help would be appreciated.

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

firstImage

Incoming: New and improved badges!

We've given our badges an overhaul and also added some brand new ones!

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

sixthImage

Power Platform World Tour

Find out where you can attend!

seventhimage

Webinars & Video Gallery

Watch & learn from the Power Automate Community Video Gallery!

Top Kudoed Authors
Users Online
Currently online: 198 members 6,492 guests
Please welcome our newest community members: