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 Automate
Unanswered

Test for Empty Array?

(2) ShareShare
ReportReport
Posted on by

Hello. I'm using the O365Users connector to look up employees in Active Directory. If an employee is NOT in AD, the response is Body: []

I cannot figure out how to determine if "[]" is true using a Condition.

I've tried 10 different Expressions including:

  • empty(array('Search_for_users'))
  • array('Search_for_users', '[]')
  • array('Search_for_users', '/[/]')
  • []
  • '[]'
  • '/[/]'
  • string('[]')
  • and every other iteration I could think of!

flowAd5.png

Can anyone assist?

Thank you

Categories:
I have the same question (0)
  • Verified answer
    Community Power Platform Member Profile Picture
    on at

    Jeez, this is crazy. Finally got this after spending MANY hours trying every variation...

    Apparently taking the Body from Search_for_users and comparing it to an empty() array...

    flowAD6.png

    Is NOT the same as adding empty() alone...

    flowAD7.png

     

    This is the type of thing that make learning Flow VERY DIFFICULT.

  • Munters Profile Picture
    34 on at

    I agree! I ran into the same problem.

    I ended up convering the body array to a string and checking if the length was less or eq to 2 ([]):

     

    length(string(body('Search_for_users')))

     

    Not very elegant but it works for me.

  • Community Power Platform Member Profile Picture
    on at

    gosh I wish I found this thread earlier... think I've gone through every iteration other than that one

  • Community Power Platform Member Profile Picture
    on at

    @RezaDorrani also showed me another method for this type of check. Might be of use to folks...

    empty(body('Search_for_users')) is equal to true
  • FrankChen Profile Picture
    21 on at

    You don't need to convert to string. you can try use length(body('Search_for_users')) equal 0

  • Community Power Platform Member Profile Picture
    on at

    Hello! And apologies for hijacking this thread slightly but I have a question on the back of it.

     

    You / OP has said "If an employee is NOT in AD, the response is Body: []"

     

    However I'm finding that the body for one particular flow / user is [] even though they ARE in AD. And I'm wondering if anyone knows why this might be? I can see the user has a handful of empty data fields within their AD user object (Job Title, Department etc) so my go-to thought is that they are being treated as a non-entity because one of these fields is empty, but I'm not sure if that's definitely the case, or which field if it is the case.

  • LadyAda Profile Picture
    6 on at

    Thank u!, it worked perfectly.

  • Munters Profile Picture
    34 on at

    You are correct. Your solution is even better. Thanks. 

  • Community Power Platform Member Profile Picture
    on at

    Hi,

     

    This seems like bug as workaround what I did is create another variable as empty array used that to compare with out value which in our case is body i believe.

     

  • Civart Profile Picture
    28 on at

    Heey,

     

    I know this is an old issue, but I write this down anyway for people new to this subject.

     

    This issue has nothing to do with Flow really and it isn't a bug. The logic you try to apply is incorrect and Flows is correct. The Condition action should have a Boolean (true or false) as input. The function empty(variable x) returns 'true' when variable x is empty or 'false' if it is not empty. In your example you want to check if 'Search_for_users' is empty, but you don’t. You check if the value of ‘Search_for_users’ is equal to the return value of the empty(variable x) function.

     

    For example: ‘Search_for_users’ doesn’t have a value (this means it’s value isn’t true or false, but empty). The function empty(‘Search_for_users’) returns true because ‘Search_for_users’ is empty. So what you are asking in your first example is: Is the body of ‘Search_for_users’ equal to the return value of empty('Search_for_users)? NO it isn’t. ‘The body for Search_for_users’ isn’t true but empty. In other words: Is null equal to true --> No it is not.

     

    Your second example DOES work because empty(‘Search_for_users’) returns true to the Condition action. In your first example you compare the body value of ‘Search_for_users’ with the return value of the empty() function, which in turn returns false to the Condition action.

     

    So your condition should be: empty(‘Search_for_users’) is equal to true.

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