Skip to main content

Notifications

Power Automate - General Discussion
Answered

How to access the value of an array

(1) ShareShare
ReportReport
Posted on by 21

Hi, is there a way to get the value of these using expression like @{first(body('Get_all_referrals')?['value'])?['id']}? I just want to get the values without using "Apply to each" action to loop inside the array of an array.

 

Capture.PNG

  • linojr_asmolo Profile Picture
    linojr_asmolo 21 on at
    Re: How to access the value of an array

    Hi @MattWeston365 , how do i append an object to an array of type variable?

    This is the schema of my variable Owner:

     

    Capture.PNG

     

    This my Append Action:

    Capture.PNG

     

    But this gives me an error.
    Do you know something about it?

  • linojr_asmolo Profile Picture
    linojr_asmolo 21 on at
    Re: How to access the value of an array

    @MattWeston365 , Yupz, i've used that in the flow to check whether it's empty. Thanks, with the syntax you've shared, that gives me an understanding of how to access array. And I was able to modify the query expression in different ways. Thanks, this is really a big help.

  • MattWeston365 Profile Picture
    MattWeston365 1,701 on at
    Re: How to access the value of an array

    Hi @linojr_asmolo you could build a number of checks in before hand to make sure that the values are there.

     

    E.g. you could use an expression: length(body('Get_all_referrals')?['value'][0]?['customerProfile']['team']) to see if it's greater than 0 (a team is present).

  • linojr_asmolo Profile Picture
    linojr_asmolo 21 on at
    Re: How to access the value of an array

    Thanks. This one works. So, as long as the ['team'] in body('Get_all_referrals')?['value'][0]?['customerProfile']['team'][0]?['email'] is not empty. 

  • linojr_asmolo Profile Picture
    linojr_asmolo 21 on at
    Re: How to access the value of an array

    Thanks. I haven't tested the expression due access limitation for now, hopefully later given permission but i managed to do the expression using the format you've given.

     

    Is that format can be also used in in this flow? They have the same JSON schema.

    Capture.PNG

     

    I got this error:


    Capture1.PNG

     

    InvalidTemplate. Unable to process template language expressions in action 'Set_variable_2' inputs at line '1' and column '2090': 'The template language expression 'body('Parse_JSON')?['value'][0]?['customerProfile']['team'][0]?['email']' cannot be evaluated because property 'value' cannot be selected. Array elements can only be selected using an integer index. Please see https://aka.ms/logicexpressions for usage details.'.

  • Verified answer
    MattWeston365 Profile Picture
    MattWeston365 1,701 on at
    Re: How to access the value of an array

    It should be something like this:

     

    body('Get_all_referrals')?['value'][0]?['customerProfile']['team'][0]?['email']

  • linojr_asmolo Profile Picture
    linojr_asmolo 21 on at
    Re: How to access the value of an array

    Thanks for your reply. How can i achieve it with this. Thanks in advance.
    Capture.PNG

  • MattWeston365 Profile Picture
    MattWeston365 1,701 on at
    Re: How to access the value of an array

    You can use either the "first" expression, or what I prefer to do is identify the exact array index. E.g. if I wanted just the first item then I could do something like this:

     

    items()?['items'][0]?['team'][0]?['properties'][0]?['email']

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

Microsoft Kickstarter Events…

Register for Microsoft Kickstarter Events…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 145,567

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,907

Leaderboard