cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Mike2500 Responsive Resident
Responsive Resident

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
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
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

FenderBerg
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?
Mike2500 Responsive Resident
Responsive Resident

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.

Highlighted
amdass 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
MBAS Gallery 2020

MBAS Gallery 2020

Watch Microsoft Business Applications Summit sessions on-demand.

firstImage

New Ranks and Rank Icons released on April 21!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power Automate Community!

firstImage

Now Live: Power Virtual Agents Community!

We are excited to announce the launch of Power Virtual Agents Community. Check it out now!

firstImage

New & Improved Power Automate Community Cookbook

We've updated and improved the layout and uploading format of the Power Automate Cookbook!

thirdimage

Power Automate Community User Group Member Badge

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

sixthImage

Community Summit North America

The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Users online (8,469)