Skip to main content

Notifications

Community site session details

Community site session details

Session Id : 2DjWL0CS3S3DzC07sKYlYB
Power Apps - Building Power Apps
Answered

Using Office365Users.SearchUserV2 to search for users by displayName AND jobTitle

Like (2) ShareShare
ReportReport
Posted on 22 Jan 2025 16:45:03 by 15
Hi all,
 
Currently have a phone directory app that works perfectly when searching for users by their display name, but we cannot figure out how to make it so we can also search by job title.
 
The current formula we are using is here:
 
Filter(
    Office365Users.SearchUserV2(
        {
            searchTerm: SearchNametxt.Text,
            top: 100
        }
    ).value,
    (
        Find("(Business name)", DisplayName) > 0 ||
        Find("(BUSINESS NAME)", DisplayName) > 0 ||
        Find("(Another BUSINESS NAME)", DisplayName) > 0 ||
        Find("(Another Business Name)", DisplayName) > 0 ||
        Find(SearchNametxt.Text, JobTitle) > 0
    ) && AccountEnabled = true
)
 
I only recently added in the Find(SearchNametxt.Text, JobTitle) > 0 line but it doesn't work. No errors but it just doesn't return any results.
 
I've tried a few other options but none of them worked either, is anyone able to let me know how I can update this formula to be able to search for either displayName or jobTitle in the same text input box?
 
 
  • MH SP Dev Profile Picture
    15 on 28 Jan 2025 at 16:07:04
    Using Office365Users.SearchUserV2 to search for users by displayName AND jobTitle
    Update:

    For anyone else who may ever come across this post looking for how to filter a gallery by a text input box and a dropdown, here is my latest update to the app.
     
    For the "OnStart" property of the App I have created a collection:
    ClearCollect(
        UsersCollection,
        Office365Users.SearchUserV2(
            {
                searchTerm: " ",
                isSearchTermRequired: false,
                top: 999
            }
        ).value
    );

    And then for the gallery's "Items" properties:
    Filter(
        UsersCollection,
        AccountEnabled &&
        (
            Dropdown1.Selected.Value = "Name" && StartsWith(DisplayName, SearchNametxt.Text) ||
            Dropdown1.Selected.Value = "Job Title" && !IsBlank(JobTitle) && StartsWith(Coalesce(JobTitle, ""), SearchNametxt.Text) ||
            Dropdown1.Selected.Value = "Department" && !IsBlank(Department) && StartsWith(Coalesce(Department, ""), SearchNametxt.Text)
        ) &&
        (
            Find("(Business Name)", DisplayName) > 0 || 
            Find("(BUSINESS NAME)", DisplayName) > 0 || 
            Find("(Another BUSINESS Name)", DisplayName) > 0 || 
            Find("(Another Business Name)", DisplayName) > 0
        )
    )
    
    For anyone wondering what the Find("(Business Name)", DisplayName) > 0 is about, I mentioned earlier in my post that these were used to filter out any service accounts as all of our user profiles will have one of our business names at the end in brackets, e.g. MH SP Dev (Business Name).
     
    It can be removed if you do not need to filter out service accounts.
  • MH SP Dev Profile Picture
    15 on 28 Jan 2025 at 11:22:58
    Using Office365Users.SearchUserV2 to search for users by displayName AND jobTitle
     
    Thank you for your assistance on this, I've got this working now!
     
    Final formula that I've used:
     
    Filter(
        Office365Users.SearchUserV2(
            {
                searchTerm: SearchNametxt.Text,
                isSearchTermRequired: false,
                top: 999
            }
        ).value,
        (Len(SearchJobtxt.Text) = 0 || SearchJobtxt.Text in JobTitle) && 
        AccountEnabled &&
        (
            Find("(Business Name)", DisplayName) > 0 || 
            Find("(BUSINESS NAME)", DisplayName) > 0 || 
            Find("(Another BUSINESS Name)", DisplayName) > 0 || 
            Find("(Another Business Name)", DisplayName) > 0
        )
    )
    Much appreciation for the help!
     
  • Verified answer
    WarrenBelz Profile Picture
    146,949 Most Valuable Professional on 27 Jan 2025 at 21:12:07
    Using Office365Users.SearchUserV2 to search for users by displayName AND jobTitle
    Yes that certainly changes the issue, however you need two separate search functions for name and job title as when you enter the job title. it will also try to match on the DisplayName.
    Filter(
       Office365Users.SearchUserV2(
          {
             searchTerm: SearchNametxt.Text,
             isSearchTermRequired: false,
             top: 999
          }
       ).value,
       (Len(SearchJobtxt.Text) = 0 || SearchJobtxt.Text in JobTitle) && AccountEnabled
    )
     
    Please click Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it a Like.
    MVP (Business Applications)    Visit my blog Practical Power Apps    LinkedIn    Buy me a coffee
  • MHSPDev Profile Picture
    65 on 27 Jan 2025 at 12:03:55
    Using Office365Users.SearchUserV2 to search for users by displayName AND jobTitle

    Could the issue be that the app was set up to use a text input box and not a combo box?
     
    The app was configured by a colleague who used a text input box but if that's potentially causing the issue we can switch it.
     
    When I enter the formula provided I'm receiving an error for the searchTerm column that it is expecting a 'Text' type and we're using an error type:
     

    We only have around 300 active users which is what the DisplayName restriction is for, probably around 700 accounts overall.

    EDIT: My apologies, I've just realised I didn't include in the post that the filter is for a GALLERY 🤦🏻‍♂️

    So the Text Input (SearchNametxt) is used to enter an employees name or job title, and then the gallery is showing the list of employees.
  • WarrenBelz Profile Picture
    146,949 Most Valuable Professional on 27 Jan 2025 at 11:43:35
    Using Office365Users.SearchUserV2 to search for users by displayName AND jobTitle
    The code works perfectly here, although without your Business Name portion
    Filter(
        Office365Users.SearchUserV2(
            {
                searchTerm: Self.SearchText,
                isSearchTermRequired: false,
                top: 999
            }
        ).value,
        (Len(SearchNametxt.Text) = 0 || SearchNametxt.Text in JobTitle) && AccountEnabled
    )
    I put some letters from the JobTitle in SearchNametxt and received all the users with the characters in their job title. I could then search using the Combo Box search input for the user's name. How many users are in your directory ?
     
    Please click Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it a Like.
    MVP (Business Applications)    Visit my blog Practical Power Apps    LinkedIn    Buy me a coffee
  • MHSPDev Profile Picture
    65 on 27 Jan 2025 at 10:49:32
    Using Office365Users.SearchUserV2 to search for users by displayName AND jobTitle
     
    Thank you for assisting, unfortunately this doesn't allow us to search for users by job title still.
     
    The values we are restricting the DisplayName to are different names of parts of the business.
     
    So users will have a DN such as "MH SP Dev (Business Name)" or (Another Business Name).
  • WarrenBelz Profile Picture
    146,949 Most Valuable Professional on 26 Jan 2025 at 21:25:36
    Using Office365Users.SearchUserV2 to search for users by displayName AND jobTitle
    There are a number of fundamental issues here that you need to address
    • You need to search for the DisplayName and Job from different places, otherwise your entered text needs to match both.
    • If you are doing the Job first, you need isSearchTermRequired: false, so it does not need the user search.
    • Use top: 999 instead of top: 100 to get a bigger data set to filter.
    • I also suggest the in filter is better than Find. (I am not sure to what values you are restricting the DisplayName to here).
    • I have also allowed for an empty Job search so the name search works without it.
    Filter(
       Office365Users.SearchUserV2(
          {
             searchTerm: Self.SearchText,
             isSearchTermRequired: false,
             top: 999
          }
       ).value,
       (
          "(Business name)" in DisplayName || 
          "(BUSINESS NAME)" in DisplayName || 
          "(Another BUSINESS NAME)" in DisplayName || 
          "(Another Business Name)" in DisplayName || 
          (
             Len(SearchNametxt.Text) = 0 || 
             SearchNametxt.Text in JobTitle
          )
       ) && AccountEnabled
    )
     
    Please click Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it a Like.
    MVP (Business Applications)    Visit my blog Practical Power Apps    LinkedIn    Buy me a coffee
  • MH SP Dev Profile Picture
    15 on 23 Jan 2025 at 07:32:19
    Using Office365Users.SearchUserV2 to search for users by displayName AND jobTitle
    @SaiRT14 unfortunately neither of those options worked, they'd let me search for the display name but not the job title.
     
    I know my job title field is not empty but it just can't find it.
  • SaiRT14 Profile Picture
    1,966 Super User 2025 Season 1 on 22 Jan 2025 at 21:30:28
    Using Office365Users.SearchUserV2 to search for users by displayName AND jobTitle
     
    Check search is case-insensitive, as Find function is case-sensitive. If you want to handle case insensitivity, you can use Lower() on both the search term and the fields:
    Filter(
        Office365Users.SearchUserV2(
            {
                searchTerm: SearchNametxt.Text,
                top: 100
            }
        ).value,
        (
            (Find(Lower(SearchNametxt.Text), Lower(DisplayName)) > 0 || 
            Find(Lower(SearchNametxt.Text), Lower(JobTitle)) > 0) 
            && AccountEnabled = true
        )
    )
     
    Check the JobTitle field is not empty before searching. If it's empty, it might return unexpected results.
    Filter(
        Office365Users.SearchUserV2(
            {
                searchTerm: SearchNametxt.Text,
                top: 100
            }
        ).value,
        (
            (Len(JobTitle) > 0 && Find(SearchNametxt.Text, JobTitle) > 0) || 
            Find(SearchNametxt.Text, DisplayName) > 0 
            && AccountEnabled = true
        )
    )
     
    pls try.
     
    thanks
     
     

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 Apps - Building Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 89 Most Valuable Professional

#2
MS.Ragavendar Profile Picture

MS.Ragavendar 60

#3
stampcoin Profile Picture

stampcoin 48

Overall leaderboard