cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Ptiwari
Helper I
Helper I

PowerApps office 365 search is not working for departments and job title

Hi,

We have created a PowerApps for our staff directory, added office 365 data connection on it.

When we searching user by name, it is showing correct result.

But when we tried to search by User department or job title ex: Accounting/HR. It is showing no results.

We are using below mentioned formula in our gallery.

Filter(Office365Users.SearchUser({searchTerm:TextInputEmp.Text}),!(IsBlank(Department)) && "companyname" in Lower(Mail))

I am not sure, why search is not working for department and job title. Please let me know if I need to make changes in my formula?

Any help is much appreciated.

Thanks

 

1 ACCEPTED SOLUTION

Accepted Solutions

@Ptiwari 

Gotcha...thought there might be that situation when you were checking the company name.

So, set your formula to this:

Filter(Office365Users.SearchUser({top:500}), 
       !IsBlank(Department) && 
       "domain" in Mail &&
       (
           TextInputEmp.Text in DisplayName || 
           TextInputEmp.Text in Department || 
           TextInputEmp.Text in JobTitle
       )
  )

You can drop (as I did) the Lower statement.  When you use the In operator, it is case insensitive, so no need to use the lower or upper functions.

 

Also, if you want your list to show all results if nothing has been entered to "search" by, then consider this formula:

Filter(Office365Users.SearchUser({top:500}), 
       !IsBlank(Department) && 
       "domain" in Mail &&
       If(IsBlank(TextInputEmp.Text), true,
             (
               TextInputEmp.Text in DisplayName || 
               TextInputEmp.Text in Department || 
               TextInputEmp.Text in JobTitle
             )
      )
  )

 

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

11 REPLIES 11
RandyHayes
Super User
Super User

@Ptiwari 

Your formula will not be able to search title or department as you are using the SearchUser function.  The SearchTerm will only search display name, given name, surname, mail, mail nickname and user principal name.  

Please see the documentation on that function here.

 

I hope that explains for you the issue.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

@RandyHayes Thank you for the quick reply.

Do you know the correct formula that search department, job title and display name?

Thanks

 

 

@Ptiwari 

You would want to do that within your filter statement.

 

Filter(
     Office365Users.SearchUser(
          {searchTerm:TextInputEmp.Text}),
     !(IsBlank(Department)) && 
     "companyname" in Lower(Mail) && 
("whatever" in Department || "Whatever" in JobTitle) )

 

 

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

@RandyHayes 

I have tried this formula but it is not showing any results.

It is showing 0 count in my search bar.

Thanks

@Ptiwari 

Please share what your formula looks like at this point.  That will help to determine where the problem may be.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

@RandyHayes 

Hi,

I have tried your formula again, it shows me a result but it is different than what I am looking.

What I am trying to do is,  create a search box that will search not only the user's name, but also search across other parameters like Job Tile and Department. So if someone types in Steve, they find all the Steves, but if they type in "market" all Marketing department members or anyone with "Market" in their title would pop up.

 

How could I search on other parameters besides the Display Name? please check the image below.

Thanks2019-06-28_9-27-00.jpg

 

@Ptiwari 

So, if I understand the pop-out annotation on your picture, you want the users to be able to type in a name, or a department, or a title and have results appear.

The formula I supplied is fairly restrictive based on your previous formula.

The formula states to return any items that are found in the searchTerm  SearchUser({searchTerm: TextInputEmp.Text})  - THEN filter those results by department not being blank, the literal text "companyname" being in the Mail column and either the word "Marketing" being in Department or "Developer" being in JobTitle.

I believe that you ultimately want to replace the hard-coded "Marketing" and "Developer" in the formula to be the TextInputEmp.Text.

This will cause an issue.  If a user wants to search for "Marketing" as a department, the first restrictive aspect is the SearchUser function because here you are searching for "Marketing" in the columns that SearchUser will search (as previously mentioned in an earlier message).  This will return nothing and thus the rest of the filter formula will be irrelevant. 

I'm not really sure what "companyname" in the Mail has to do with your searching unless you are somehow dealing with multiple domains in your tenant.

So, based on the above, I would suggest the following formula for your Items property:

 

Filter(Office365Users.SearchUser(), 
TextInputEmp.Text in DisplayName ||
TextInputEmp.Text in Department ||
TextInputEmp.Text in JobTitle)

This will provide what appears to be your requirement in your picture annotation.

 

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

@RandyHayes 

Yes, we are hosting multiple domain in our tenant. That's why I added company name in my previous formula (so that I can show only 1 domain results in my gallery). I modified your formula little bit, it started showing me results based on Department/Job Title/User Name. But it showing other domain users also in my gallery. Added screen shot also for the reference. Now I need to figure it out how can I show only 1 domain result in my gallery/search? Thank you so much for your help. I really appreciate that. Please let me know how can I search results just for single domain? 

 

2019-06-28_11-34-26.jpg

 

@Ptiwari 

Gotcha...thought there might be that situation when you were checking the company name.

So, set your formula to this:

Filter(Office365Users.SearchUser({top:500}), 
       !IsBlank(Department) && 
       "domain" in Mail &&
       (
           TextInputEmp.Text in DisplayName || 
           TextInputEmp.Text in Department || 
           TextInputEmp.Text in JobTitle
       )
  )

You can drop (as I did) the Lower statement.  When you use the In operator, it is case insensitive, so no need to use the lower or upper functions.

 

Also, if you want your list to show all results if nothing has been entered to "search" by, then consider this formula:

Filter(Office365Users.SearchUser({top:500}), 
       !IsBlank(Department) && 
       "domain" in Mail &&
       If(IsBlank(TextInputEmp.Text), true,
             (
               TextInputEmp.Text in DisplayName || 
               TextInputEmp.Text in Department || 
               TextInputEmp.Text in JobTitle
             )
      )
  )

 

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Users online (1,285)