cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Continued Contributor
Continued Contributor

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
Highlighted
Community Support
Community Support

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
Highlighted
Community Support
Community Support

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

Highlighted
New Member

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?
Highlighted
Continued Contributor
Continued Contributor

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.

Advocate I
Advocate I

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
FirstImage

Microsoft Ignite 2020

Check out the announcement of Power Platform content at Microsoft Ignite!

thirdImage

Experience what's new for Power Automate

Join us for an in-depth look at the new Power Automate features and capabilities at the free Microsoft Business Applications Launch Event.

firstImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (3,211)