cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ericonline
Community Champion
Community Champion

Test for Empty Array?

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

1 ACCEPTED SOLUTION

Accepted Solutions
ericonline
Community Champion
Community Champion

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.

View solution in original post

17 REPLIES 17
ericonline
Community Champion
Community Champion

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.

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.

Anonymous
Not applicable

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

@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

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

Anonymous
Not applicable

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.

Thank u!, it worked perfectly.

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

Anonymous
Not applicable

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.

 

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.

diavoloplanas
New Member

hi im form mexico im going to try use my best

 

im trying to put this on my flow empty(body('buscar_usuarios_(V2)'))  but always say true i try to use @ but in my flow say that this ewxpression its grong

 

i dont now what to do now 

diavoloplanas_0-1634087304688.png

 

 

i try all the answers in this 

what im doing wrong =(

my result ist not true always its false

diavoloplanas_0-1634088656238.png

 

 

i have this error message

"La función de lenguaje de plantilla "length" espera que su parámetro sea una matriz o una cadena. El valor que se ha proporcionado es de tipo "Object"

 

 

 

Hello diavoloplanas,

 

The error La función de lenguaje de plantilla "length" espera que su parámetro sea una matriz o una cadena. El valor que se ha proporcionado es de tipo "Object" is saying that you gave an object to the length function. However, the length function can only have a string or an array as input. This is logical because the function should be able to count something.

 

String

A string exists out of characters. The string "hello" has 5 characters, so the length function will return 5.

 

Array

An array exists out of elements. The length function counts the number of elements, for example:

["Green", "Blue", "Red"] <-- this array has 3 elements: green, blue and red. So the function returns 3. 

 

Object

For an object there is no way the function understands what the length is because an object can exist out of anything. An object can have multiple properties. For example:

 

{

"Haircolor": "Brown",

"Eyecolor": "Blue",

"Height": 182,

"Age": 33,

"Brothers": ["Jason", "Alex"]

}

 

The properties of this object are: haircolor, eyecolor, height, age and brothers. The length function can count the number of characters in the property haircolor or eyecolor and the number of elements in the property brothers. So you should provide the length-function one of these properties and not the object itself.

 

Empty() function

For the empty() function you can provide an object as a parameter. If the object doesn't have anything (null) the function will return true. If it's not empty (not null) then it will return false. If the empty function tells you that body(buscar_usuarios_(V2)) is empty than the body properly is empty.

 

What to do?

When you run the flow, you can see the output of the Buscar Usuarios (V2) action. Can you please tell me what is in there? That way I might be able to help you.

 

Kind regards,

Civ

I also used length to solve this issue. But, I want to call out that when used on an array, it counts the objects in the array vs the characters. I tested to confirm this by initializing an integer and setting its value to the same function, length(body('Filter_array'))

dangthis_0-1635946457965.png

Which yielded this result

dangthis_2-1635946622781.png

At face value, we see that there is more than 4 characters there. Loading the raw output from the filter array into a JSON viewer, we see there are 4 objects

dangthis_3-1635946785316.png

So to simplify the Flow, you dont have to convert the array to a string, just set your condition to greater than 0

dangthis_4-1635947098150.png

 

Jfranz
Frequent Visitor

Just adding my experience to this since even with all the above awesome information I still struggled. Below is my flow, I have a Get Items that is looking for a specific item in a list. When it doesn't find anything it returns an empty array. So for testing purposes I set my variable to be an array with the results of the filter - that checked out so I created a compose that will return a value of true or false if the array is empty. The function in the compose is 

empty(variables('FilteredArray')) FILTEREDARRAY is the name of my variable. Then in my condition I had to set the outcome of the compose to equal the function false - if I just typed in false it would not work. I think for a cleaner flow I could get rid of the array variable and just achieve this in the condition but it JUST wouldn't go.

 

my workaroundmy workaround

I had a similar issue.  I also recommend checking the "Configure Run After" setting of your Condition Control connector.  In my scenario, the default was for the condition control to only run if the Search for User previous step was successful.   If you want the Condition control to run after Search returns a "user not found", you need to change the Configure Run After setting.   

 

allan_t_0-1697133726739.png

 

The default was to only run after success.  I selected all options, then it ran as expected.  

 

allan_t_1-1697133869321.png

 

 

wcavarra
Regular Visitor

Thank you for taking the time to submit your solution, it was very helpful.

Helpful resources

Announcements

Tuesday Tip: Getting Started with Private Messages & Macros

Welcome to TUESDAY TIPS, your weekly connection with the most insightful tips and tricks that empower both newcomers and veterans in the Power Platform Community! Every Tuesday, we bring you a curated selection of the finest advice, distilled from the resources and tools in the Community. Whether you’re a seasoned member or just getting started, Tuesday Tips are the perfect compass guiding you across the dynamic landscape of the Power Platform Community.   As our community family expands each week, we revisit our essential tools, tips, and tricks to ensure you’re well-versed in the community’s pulse. Keep an eye on the News & Announcements for your weekly Tuesday Tips—you never know what you may learn!   This Week's Tip: Private Messaging & Macros in Power Apps Community   Do you want to enhance your communication in the Community and streamline your interactions? One of the best ways to do this is to ensure you are using Private Messaging--and the ever-handy macros that are available to you as a Community member!   Our Knowledge Base article about private messaging and macros is the best place to find out more. Check it out today and discover some key tips and tricks when it comes to messages and macros:   Private Messaging: Learn how to enable private messages in your community profile and ensure you’re connected with other community membersMacros Explained: Discover the convenience of macros—prewritten text snippets that save time when posting in forums or sending private messagesCreating Macros: Follow simple steps to create your own macros for efficient communication within the Power Apps CommunityUsage Guide: Understand how to apply macros in posts and private messages, enhancing your interaction with the Community For detailed instructions and more information, visit the full page in your community today:Power Apps: Enabling Private Messaging & How to Use Macros (Power Apps)Power Automate: Enabling Private Messaging & How to Use Macros (Power Automate)  Copilot Studio: Enabling Private Messaging &How to Use Macros (Copilot Studio) Power Pages: Enabling Private Messaging & How to Use Macros (Power Pages)

Tuesday Tip: Subscriptions & Notifications

TUESDAY TIPS are our way of communicating helpful things we've learned or shared that have helped members of the Community. Whether you're just getting started or you're a seasoned pro, Tuesday Tips will help you know where to go, what to look for, and navigate your way through the ever-growing--and ever-changing--world of the Power Platform Community! We cover basics about the Community, provide a few "insider tips" to make your experience even better, and share best practices gleaned from our most active community members and Super Users.   With so many new Community members joining us each week, we'll also review a few of our "best practices" so you know just "how" the Community works, so make sure to watch the News & Announcements each week for the latest and greatest Tuesday Tips!   This Week: All About Subscriptions & Notifications We don't want you to a miss a thing in the Community! The best way to make sure you know what's going on in the News & Announcements, to blogs you follow, or forums and galleries you're interested in is to subscribe! These subscriptions ensure you receive automated messages about the most recent posts and replies. Even better, there are multiple ways you can subscribe to content and boards in the community! (Please note: if you have created an AAD (Azure Active Directory) account you won't be able to receive e-mail notifications.)   Subscribing to a Category  When you're looking at the entire category, select from the Options drop down and choose Subscribe.     You can then choose to Subscribe to all of the boards or select only the boards you want to receive notifications. When you're satisfied with your choices, click Save.     Subscribing to a Topic You can also subscribe to a single topic by clicking Subscribe from the Options drop down menu, while you are viewing the topic or in the General board overview, respectively.     Subscribing to a Label Find the labels at the bottom left of a post.From a particular post with a label, click on the label to filter by that label. This opens a window containing a list of posts with the label you have selected. Click Subscribe.     Note: You can only subscribe to a label at the board level. If you subscribe to a label named 'Copilot' at board #1, it will not automatically subscribe you to an identically named label at board #2. You will have to subscribe twice, once at each board.   Bookmarks Just like you can subscribe to topics and categories, you can also bookmark topics and boards from the same menus! Simply go to the Topic Options drop down menu to bookmark a topic or the Options drop down to bookmark a board. The difference between subscribing and bookmarking is that subscriptions provide you with notifications, whereas bookmarks provide you a static way of easily accessing your favorite boards from the My subscriptions area.   Managing & Viewing Your Subscriptions & Bookmarks To manage your subscriptions, click on your avatar and select My subscriptions from the drop-down menu.     From the Subscriptions & Notifications tab, you can manage your subscriptions, including your e-mail subscription options, your bookmarks, your notification settings, and your email notification format.     You can see a list of all your subscriptions and bookmarks and choose which ones to delete, either individually or in bulk, by checking multiple boxes.     A Note on Following Friends on Mobile Adding someone as a friend or selecting Follow in the mobile view does not allow you to subscribe to their activity feed. You will merely be able to see your friends’ biography, other personal information, or online status, and send messages more quickly by choosing who to send the message to from a list, as opposed to having to search by username.

Monthly Community User Group Update | April 2024

The monthly Community User Group Update is your resource for discovering User Group meetings and events happening around the world (and virtually), welcoming new User Groups to our Community, and more! Our amazing Community User Groups are an important part of the Power Platform Community, with more than 700 Community User Groups worldwide, we know they're a great way to engage personally, while giving our members a place to learn and grow together.   This month, we welcome 3 new User Groups in India, Wales, and Germany, and feature 8 User Group Events across Power Platform and Dynamics 365. Find out more below. New Power Platform User Groups   Power Platform Innovators (India) About: Our aim is to foster a collaborative environment where we can share upcoming Power Platform events, best practices, and valuable content related to Power Platform. Whether you’re a seasoned expert or a newcomer looking to learn, this group is for you. Let’s empower each other to achieve more with Power Platform. Join us in shaping the future of digital transformation!   Power Platform User Group (Wales) About: A Power Platform User Group in Wales (predominantly based in Cardiff but will look to hold sessions around Wales) to establish a community to share learnings and experience in all parts of the platform.   Power Platform User Group (Hannover) About: This group is for anyone who works with the services of Microsoft Power Platform or wants to learn more about it and no-code/low-code. And, of course, Microsoft Copilot application in the Power Platform.   New Dynamics365 User Groups   Ellucian CRM Recruit UK (United Kingdom) About: A group for United Kingdom universities using Ellucian CRM Recruit to manage their admissions process, to share good practice and resolve issues.    Business Central Mexico (Mexico City) About:  A place to find documentation, learning resources, and events focused on user needs in Mexico. We meet to discuss and answer questions about the current features in the standard localization that Microsoft provides, and what you only find in third-party locations. In addition, we focus on what's planned for new standard versions, recent legislation requirements, and more. Let's work together to drive request votes for Microsoft for features that aren't currently found—but are indispensable.   Dynamics 365 F&O User Group (Dublin) About: The Dynamics 365 F&O User Group - Ireland Chapter meets up in person at least twice yearly in One Microsoft Place Dublin for users to have the opportunity to have conversations on mutual topics, find out what’s new and on the Dynamics 365 FinOps Product Roadmap, get insights from customer and partner experiences, and access to Microsoft subject matter expertise.  Upcoming Power Platform Events    PAK Time (Power Apps Kwentuhan) 2024 #6 (Phillipines, Online) This is a continuation session of Custom API. Sir Jun Miano will be sharing firsthand experience on setting up custom API and best practices. (April 6, 2024)       Power Apps: Creating business applications rapidly (Sydney) At this event, learn how to choose the right app on Power Platform, creating a business application in an hour, and tips for using Copilot AI. While we recommend attending all 6 events in the series, each session is independent of one another, and you can join the topics of your interest. Think of it as a “Hop On, Hop Off” bus! Participation is free, but you need a personal computer (laptop) and we provide the rest. We look forward to seeing you there! (April 11, 2024)     April 2024 Cleveland Power Platform User Group (Independence, Ohio) Kickoff the meeting with networking, and then our speaker will share how to create responsive and intuitive Canvas Apps using features like Variables, Search and Filtering. And how PowerFx rich functions and expressions makes configuring those functionalities easier. Bring ideas to discuss and engage with other community members! (April 16, 2024)     Dynamics 365 and Power Platform 2024 Wave 1 Release (NYC, Online) This session features Aric Levin, Microsoft Business Applications MVP and Technical Architect at Avanade and Mihir Shah, Global CoC Leader of Microsoft Managed Services at IBM. We will cover some of the new features and enhancements related to the Power Platform, Dataverse, Maker Portal, Unified Interface and the Microsoft First Party Apps (Microsoft Dynamics 365) that were announced in the Microsoft Dynamics 365 and Power Platform 2024 Release Wave 1 Plan. (April 17, 2024)     Let’s Explore Copilot Studio Series: Bot Skills to Extend Your Copilots (Makati National Capital Reg... Join us for the second installment of our Let's Explore Copilot Studio Series, focusing on Bot Skills. Learn how to enhance your copilot's abilities to automate tasks within specific topics, from booking appointments to sending emails and managing tasks. Discover the power of Skills in expanding conversational capabilities. (April 30, 2024)   Upcoming Dynamics365 Events    Leveraging Customer Managed Keys (CMK) in Dynamics 365 (Noida, Uttar Pradesh, Online) This month's featured topic: Leveraging Customer Managed Keys (CMK) in Dynamics 365, with special guest Nitin Jain from Microsoft. We are excited and thankful to him for doing this session. Join us for this online session, which should be helpful to all Dynamics 365 developers, Technical Architects and Enterprise architects who are implementing Dynamics 365 and want to have more control on the security of their data over Microsoft Managed Keys. (April 11, 2024)       Stockholm D365 User Group April Meeting (Stockholm) This is a Swedish user group for D365 Finance and Operations, AX2012, CRM, CE, Project Operations, and Power BI.  (April 17, 2024)         Transportation Management in D365 F&SCM Q&A Session (Toronto, Online) Calling all Toronto UG members and beyond! Join us for an engaging and informative one-hour Q&A session, exclusively focused on Transportation Management System (TMS) within Dynamics 365 F&SCM. Whether you’re a seasoned professional or just curious about TMS, this event is for you. Bring your questions! (April 26, 2024)   Leaders, Create Your Events!    Leaders of existing User Groups, don’t forget to create your events within the Community platform. By doing so, you’ll enable us to share them in future posts and newsletters. Let’s spread the word and make these gatherings even more impactful! Stay tuned for more updates, inspiring stories, and collaborative opportunities from and for our Community User Groups.   P.S. Have an event or success story to share? Reach out to us – we’d love to feature you. Just leave a comment or send a PM here in the Community!

Exclusive LIVE Community Event: Power Apps Copilot Coffee Chat with Copilot Studio Product Team

We have closed kudos on this post at this time. Thank you to everyone who kudo'ed their RSVP--your invitations are coming soon!  Miss the window to RSVP? Don't worry--you can catch the recording of the meeting this week in the Community.  Details coming soon!   *****   It's time for the SECOND Power Apps Copilot Coffee Chat featuring the Copilot Studio product team, which will be held LIVE on April 3, 2024 at 9:30 AM Pacific Daylight Time (PDT).     This is an incredible opportunity to connect with members of the Copilot Studio product team and ask them anything about Copilot Studio. We'll share our special guests with you shortly--but we want to encourage to mark your calendars now because you will not want to miss the conversation.   This live event will give you the unique opportunity to learn more about Copilot Studio plans, where we’ll focus, and get insight into upcoming features. We’re looking forward to hearing from the community, so bring your questions!   TO GET ACCESS TO THIS EXCLUSIVE AMA: Kudo this post to reserve your spot! Reserve your spot now by kudoing this post.  Reservations will be prioritized on when your kudo for the post comes through, so don't wait! Click that "kudo button" today.   Invitations will be sent on April 2nd.Users posting Kudos after April 2nd at 9AM PDT may not receive an invitation but will be able to view the session online after conclusion of the event. Give your "kudo" today and mark your calendars for April 3, 2024 at 9:30 AM PDT and join us for an engaging and informative session!

Tuesday Tip: Blogging in the Community is a Great Way to Start

TUESDAY TIPS are our way of communicating helpful things we've learned or shared that have helped members of the Community. Whether you're just getting started or you're a seasoned pro, Tuesday Tips will help you know where to go, what to look for, and navigate your way through the ever-growing--and ever-changing--world of the Power Platform Community! We cover basics about the Community, provide a few "insider tips" to make your experience even better, and share best practices gleaned from our most active community members and Super Users.   With so many new Community members joining us each week, we'll also review a few of our "best practices" so you know just "how" the Community works, so make sure to watch the News & Announcements each week for the latest and greatest Tuesday Tips!   This Week's Topic: Blogging in the Community Are you new to our Communities and feel like you may know a few things to share, but you're not quite ready to start answering questions in the forums? A great place to start is the Community blog! Whether you've been using Power Platform for awhile, or you're new to the low-code revolution, the Community blog is a place for anyone who can write, has some great insight to share, and is willing to commit to posting regularly! In other words, we want YOU to join the Community blog.    Why should you consider becoming a blog author? Here are just a few great reasons. 🎉   Learn from Each Other: Our community is like a bustling marketplace of ideas. By sharing your experiences and insights, you contribute to a dynamic ecosystem where makers learn from one another. Your unique perspective matters! Collaborate and Innovate: Imagine a virtual brainstorming session where minds collide, ideas spark, and solutions emerge. That’s what our community blog offers—a platform for collaboration and innovation. Together, we can build something extraordinary. Showcase the Power of Low-Code: You know that feeling when you discover a hidden gem? By writing about your experience with your favorite Power Platform tool, you’re shining a spotlight on its capabilities and real-world applications. It’s like saying, “Hey world, check out this amazing tool!” Earn Trust and Credibility: When you share valuable information, you become a trusted resource. Your fellow community members rely on your tips, tricks, and know-how. It’s like being the go-to friend who always has the best recommendations. Empower Others: By contributing to our community blog, you empower others to level up their skills. Whether it’s a nifty workaround, a time-saving hack, or an aha moment, your words have impact. So grab your keyboard, brew your favorite beverage, and start writing! Your insights matter and your voice counts! With every blog shared in the Community, we all do a better job of tackling complex challenges with gusto. 🚀 Welcome aboard, future blog author! ✍️💻🌟 Get started blogging across the Power Platform Communities today! Just follow one of the links below to begin your blogging adventure.   Power Apps: https://powerusers.microsoft.com/t5/Power-Apps-Community-Blog/bg-p/PowerAppsBlog Power Automate: https://powerusers.microsoft.com/t5/Power-Automate-Community-Blog/bg-p/MPABlog Copilot Studio: https://powerusers.microsoft.com/t5/Copilot-Studio-Community-Blog/bg-p/PVACommunityBlog Power Pages: https://powerusers.microsoft.com/t5/Power-Pages-Community-Blog/bg-p/mpp_blog   When you follow the link, look for the Message Admins button like this on the page's right rail, and let us know you're interested. We can't wait to connect with you and help you get started. Thanks for being part of our incredible community--and thanks for becoming part of the community blog!

Launch Event Registration: Redefine What's Possible Using AI

  Join Microsoft product leaders and engineers for an in-depth look at the latest features in Microsoft Dynamics 365 and Microsoft Power Platform. Learn how advances in AI and Microsoft Copilot can help you connect teams, processes, and data, and respond to changing business needs with greater agility. We’ll share insights and demonstrate how 2024 release wave 1 updates and advancements will help you:   Streamline business processes, automate repetitive tasks, and unlock creativity using the power of Copilot and role-specific insights and actions. Unify customer data to optimize customer journeys with generative AI and foster collaboration between sales and marketing teams. Strengthen governance with upgraded tools and features. Accelerate low-code development  using natural language and streamlined tools. Plus, you can get answers to your questions during our live Q&A chat! Don't wait--register today by clicking the image below!      

Users online (4,621)