cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Mike2500
Super User
Super User

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
v-micsh-msft
Community Support
Community Support

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

7 REPLIES 7
v-micsh-msft
Community Support
Community Support

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.
Anonymous
Not applicable

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?

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

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.

philone
New Member

Resurrecting an old thread because it's the top search result. If you want to select all single items with a very minimal expression I recommend doing it like this:

 

Create a parse JSON step for the whole array, put the schema for the whole array, we'll call it JSONA

Create a second parse JSON step and simply enter expression "body('JSONA')?[0]" and use a single item as the schema. We'll call this JSONI

Reference the auto generated items from JSONI to select the items without needing a loop. You can also use other expressions in place of the body expression to select say the last item instead but still only need the single expression without referencing individual items

 

JSON Single Item.jpg

roosi_Chris
Frequent Visitor

@philone  Absolute gamechanger for me, thanks for the explanation. Exactly what i was looking for!

DonPepe
Frequent Visitor

Hi @philone ,

 

This error appears when I try your code like this: 

@first(body('Filtrer_un_tableau')?['Value'])?['LastModified']

"Unable to process template language expressions in 'Message' action inputs at row '0' and column '0': 'Unable to evaluate template language expression 'first(body(' Filter_an_array')?['Value'])?['LastModified']", because the "Value" property cannot be selected. Array elements can be selected only using an integer index. For usage details, see https://aka.ms/logicexpressions. ".

 

Do you know where it could be from ? 

I just try to get the last modified file of the array.

 

Thanks for your help,

 

Don

Helpful resources

Announcements
 WHAT’S NEXT AT MICROSOFT IGNITE 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Register for a Free Workshop.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

Users online (2,198)