web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Get access to single e...
Power Automate
Unanswered

Get access to single element of array outside of loop

(0) ShareShare
ReportReport
Posted on by 1,247 Super User 2024 Season 1

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.

Categories:
I have the same question (0)
  • Verified answer
    v-micsh-msft Profile Picture
    on at

    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 Power Platform Member Profile Picture
    on at

    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 Profile Picture
    1,247 Super User 2024 Season 1 on at

    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 Profile Picture
    2 on at

    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 Profile Picture
    6 on at

    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 Profile Picture
    31 on at

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

  • DonPepe Profile Picture
    24 on at

    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

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 538 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 405 Moderator

#3
abm abm Profile Picture

abm abm 252 Most Valuable Professional

Last 30 days Overall leaderboard