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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Office365Users.SearchU...
Power Apps
Answered

Office365Users.SearchUserV2 - Search by DisplayName or Department

(0) ShareShare
ReportReport
Posted on by 11

Hello,


I am currently developing a Phone Directory PowerApp in which I can search for a user by DisplayName (First name or last name) and Department.

 

I currently have the Items property of the gallery set to:

 

 

If(
 !IsBlank(Trim(SearchBox.Text)),
 Filter(
 Office365Users.SearchUserV2(
 {
 isSearchTermRequired: false,
 top: 2000
 }
 ).value,
 AccountEnabled = true,
 !IsBlank(JobTitle) && !IsBlank(Surname) && (SearchBox.Text in DisplayName || SearchBox.Text in Department)
 )
)

 

 

 

I have several filters to not display users without a job title or a surname as this will allow me to search by DisplayName and Department however it is not returning any users past the letter "S".

 

If I change "isSearchTermRequired: false" to "searchTerm: SearchBox.Text" i am able to pull the entire list of users but not able to search by Department.

Any help is appreciated. 


Thanks!

Categories:
I have the same question (0)
  • Verified answer
    Sundeep_Malik Profile Picture
    6,501 on at

    Hey @EAscencio 

     

    You can write a similar expression:

     

    If(
    !IsBlank(Trim(SearchBox.Text)),
    Filter(
    Office365Users.SearchUserV2(
    {
    isSearchTermRequired: true,
    searchTerm: SearchBox.Text, // Use the search term
    top: 2000
    }
    ).value,
    AccountEnabled = true,
    !IsBlank(JobTitle) && !IsBlank(Surname) &&
    (SearchBox.Text in DisplayName || SearchBox.Text in Department)
    )
    )

     

    I hope this helps 🙂

  • EAscencio Profile Picture
    11 on at

    Thank you so much, this worked like a charm! 

  • EAscencio Profile Picture
    11 on at

    I'm sorry, I may have spoken too soon out of excitement. However I am still not able to search for users with the same Department. 

  • Sundeep_Malik Profile Picture
    6,501 on at

    @EAscencio 

     

    Try this :

     

    If(
    !IsBlank(Trim(SearchBox.Text)),
    Filter(
    Office365Users.SearchUserV2(
    {
    searchTerm: SearchBox.Text, // Use searchTerm instead of isSearchTermRequired
    top: 2000
    }
    ).value,
    AccountEnabled = true,
    !IsBlank(JobTitle) && !IsBlank(Surname) && (SearchBox.Text in DisplayName || SearchBox.Text in Department)
    )
    )

  • Sundeep_Malik Profile Picture
    6,501 on at

    Hey @EAscencio 

     

    I used this and it worked try this:

     

    Filter(
    Office365Users.SearchUser(
    {searchTerm: TextInput7.Text, top: 500}),
    StartsWith(Department, DropdownDepartment.Selected.Value)
    )

     

    I made a dropdown and in it I kept some departments. You can keep more:

    [
    "Human Resources",
    "Information Technology (IT)",
    "Finance",
    "Sales",
    "Marketing",
    "Customer Support",
    "Research and Development (R&D)",
    "Operations",
    "Production",
    "Quality Assurance",
    "Legal",
    "Administration",
    "Engineering",
    "Logistics",
    "Management"
    ]

  • EAscencio Profile Picture
    11 on at

    Hmm i think this solution would require me to manually manage the department names. Is it not possible to search for users based on Username or Department in the SearchBox? 

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Valantis Profile Picture

Valantis 483

#2
WarrenBelz Profile Picture

WarrenBelz 399 Most Valuable Professional

#3
11manish Profile Picture

11manish 327

Last 30 days Overall leaderboard