Skip to main content

Notifications

Community site session details

Community site session details

Session Id : zw9zwaSCwEWwz8+cyZEAsB
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 206

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.

  • PabloRoldan Profile Picture
    206 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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

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

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Automate - General Discussion

#1
rpersad Profile Picture

rpersad 16

#2
David_MA Profile Picture

David_MA 10 Super User 2025 Season 1

#3
Michael E. Gernaey Profile Picture

Michael E. Gernaey 8 Super User 2025 Season 1

Overall leaderboard
Loading started