web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id : CEpSN4mWOgjs83JEmy8ZRI
Power Apps - Building Power Apps
Answered

Creating collection of users from Office 365

Like (0) ShareShare
ReportReport
Posted on 1 Aug 2022 16:54:06 by 109

I'm trying to form a collection of users from the "Office 365 Users" connector dependent on their email address. The issue I'm running into is I'm not sure what the second input of my Collect() function should be. I want to be able to add the "whole user" to my collection and not just their display name, email, etc. For example the, the following code produces a collection of just the users display names. 

ForAll(
 Office365Users.SearchUser(),
 If(
 Last(Split(Mail, "@")).Result = "companyEmail.com",
 Collect(users_collection, DisplayName)
 )
)

The problem arises when I want to populate a gallery pulled from this collection and display more than just their name in each cell, such as an email or location. So is there any way to make a collection of the user objects themselves?

I have the same question (0)
  • _sigmaNot_ Profile Picture
    49 on 05 Apr 2023 at 19:21:41
    Re: Creating collection of users from Office 365

    @shoog - Thanks for getting back to me on this.

     

    I had tried this approach before but unfortunately doesn't work in my case as there's probably close to 100K users in the tenant I'm working with. 

     

    I ended up using PowerAutomate and Azure AD connector to meet my requirements.

  • shoog Profile Picture
    2,164 on 05 Apr 2023 at 14:25:32
    Re: Creating collection of users from Office 365

    It only looks at the beginning, so you would have to use a Filter expression around SearchUser, like this:

    Filter(Office365Users.SearchUserV2({isSearchTermRequired: false}).value, "@mydomain.com" in Mail))
  • _sigmaNot_ Profile Picture
    49 on 04 Apr 2023 at 16:13:56
    Re: Creating collection of users from Office 365

    Hi @shoog ,

     

    I'm not able to get this to work.  Does searchterm look in any part of the value or only the beginning?

    Is it possible to add wild cards into the actual searchterm?

    Example:

    Office365Users.SearchUser({searchTerm: "*@mydomain.com"})

     Sorry if this has been answered somewhere else before.  I haven't had luck finding any detailed documentation for the Office365Users connector and it's methods 🙁

  • Verified answer
    shoog Profile Picture
    2,164 on 01 Aug 2022 at 18:48:24
    Re: Creating collection of users from Office 365

    To answer your question: replacing DisplayName with ThisRecord will do the trick.

     

    However, I would recommend passing {searchterm: <at> companyname.com} to the searchuser function to prevent having to use ForAll, which is known to be slow with large datasets. You can then just collect the entire output of that function.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Telen Wang – Community Spotlight

We are honored to recognize Telen Wang as our August 2025 Community…

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 637 Most Valuable Professional

#2
stampcoin Profile Picture

stampcoin 570 Super User 2025 Season 2

#3
Power Apps 1919 Profile Picture

Power Apps 1919 473

Loading complete