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 Platform Community / Forums / Power Apps / Using Office365Users.S...
Power Apps
Answered

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

(2) ShareShare
ReportReport
Posted on 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?
 
 
Categories:
I have the same question (0)
  • SaiRT14 Profile Picture
    1,990 Super User 2025 Season 2 on at
     
    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
     
     
  • MH SP Dev Profile Picture
    15 on at
    @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.
  • WarrenBelz Profile Picture
    153,073 Most Valuable Professional on at
    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
  • MHSPDev Profile Picture
    65 on at
     
    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
    153,073 Most Valuable Professional on at
    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   
  • MHSPDev Profile Picture
    65 on at

    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.
  • Verified answer
    WarrenBelz Profile Picture
    153,073 Most Valuable Professional on at
    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
  • MH SP Dev Profile Picture
    15 on at
     
    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!
     
  • MH SP Dev Profile Picture
    15 on at
    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.

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 Apps

#1
WarrenBelz Profile Picture

WarrenBelz 721 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 320 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard