Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Automate - General Discussion
Unanswered

How to check item exists in Array of Objects using "contains" expression?

Like (0) ShareShare
ReportReport
Posted on 3 Jan 2022 08:43:38 by 283

Hi,

contains   - this expression in array can tell if element exists or not,(true/false)

for a simple array of number it works just as expected

PabloRoldan_0-1641199183342.png

Expression: contains(variables('ArrayNumber'),5)

PabloRoldan_1-1641199193813.png

result True

 

BUT

 

How to know if object exists in array using contains?

PabloRoldan_2-1641199293283.png

 

using contains how can I know if this arrays contains id = 2 o id = 3

 

  • yevreeva Profile Picture
    33 on 30 Nov 2022 at 17:23:22
    Re: How to check item exists in Array of Objects using "contains" expression?

    After struggling to find an answer to this exact question, and nearly giving up I was able to come up with a solution that's so simple, it hurts :). Simply envelop your variable (or your array) in a "string" (thus converting it to a string) to be able to search all of its content. For your example it would be:

    contains(string(variables('ArrayNumber')),'5')

     

    In my case, I had the following output from a SharePoint choice column that I was checking if a value exists:

    [{"@odata.type":"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference","Id":0,"Value":"NORTH"},{"@odata.type":"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference","Id":1,"Value":"SOUTH"}]

     

    I used following formula to check:

    contains(string(items('Apply_to_each')?['Platform'], 'NORTH')

    which returned "true" as expected.

  • Pablo Roldan Profile Picture
    283 on 11 Jan 2022 at 19:35:53
    Re: How to check item exists in Array of Objects using "contains" expression?

    Hi, With contains function then...

    contains('<collection>', '<value>')

    can I pass a object to that function and validate if exist or not?

     

     

     

     

     

    [
    {
    "id":1,
    "nombre":"Kate"
    },
    {
    "id":2,
    "nombre":"Ana"
    }
    ] 

     

     

     

     

    in a compose node I set this expression

    PabloRoldan_0-1641945949548.png

     

    contains(variables('ArrayFromAbove'), 'HOW TO PLACE THE OBJECT HERE LIKE ID = 2 , I DON'T KNOW WHAT TO PLACE HERE?')

     

     

    if it's not possible then i think I will use more action nodes like filter or iterate as you suggests

    Thanks.

  • mahoneypat Profile Picture
    1,720 on 04 Jan 2022 at 01:29:15
    Re: How to check item exists in Array of Objects using "contains" expression?

    You can add a Filter step with your PeopleArray as input where the expression below equals true, and the check if the length() of the array from the Filter step is >0.

     

    contains(createArray(2,3), item()?['id'])

     

    Pat

  • tapan Profile Picture
    Microsoft Employee on 03 Jan 2022 at 19:15:12
    Re: How to check item exists in Array of Objects using "contains" expression?

    one naĂŻve solution, I can think of is you can convert the object into JSON and iterate over the records in json to check if the value exist in array or not

  • jinivthakkar Profile Picture
    4,179 on 03 Jan 2022 at 12:33:38
    Re: How to know if element exists in Array of Objects using contains expression?

    @PabloRoldan please see if this helps, I think it is a similar usecase

     

    https://powerusers.microsoft.com/t5/General-Power-Automate/How-to-validate-if-a-item-exists-in-array-of-objects/td-p/1212407

     

    --------------------------------------------------------------------------------

    If this post helps answer your question, please click on “Accept as Solution” to help other members find it more quickly. If you thought this post was helpful, please give it a Thumbs Up.

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

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Leaderboard > Power Automate - General Discussion

#1
stampcoin Profile Picture

stampcoin 29

#2
Pstork1 Profile Picture

Pstork1 22 Most Valuable Professional

#3
David_MA Profile Picture

David_MA 20 Super User 2025 Season 1

Overall leaderboard
Loading started