BrianC987
BrianC987

Reputation: 181

Power Apps combo box not searching unique list of job titles

I have a combo box that is pulling unique job titles from O365, but it's not searching the list of job titles. It does pull a list and you can select one just the search isn't working.

In the Items field of the combo box, I have the following:

Sort(
  Distinct(
    Filter(
      Office365Users.SearchUser({searchTerm:ComboBox2.SearchText,top:999}),
      !IsBlank(JobTitle)),
    JobTitle),
  Value,
  SortOrder.Ascending)

The primary text and SearchField text of the Fields property both have Value selected. This is the only choice I have. I'm not able to select Job Title.

What do I need to do so that I can search the list of job titles?

Upvotes: 1

Views: 851

Answers (3)

BrianC987
BrianC987

Reputation: 181

For anyone that comes across this later here is what I ended up doing.

In the OnVisible property of the edit form I put:
ClearCollect(colJobTitles,SortByColumns( Filter( ShowColumns( Office365Users.SearchUser({top:999}),"JobTitle","Department"),!IsBlank(JobTitle)),"JobTitle",SortOrder.Ascending));

and in the items property, I used:
Distinct(Filter(colJobTitles,Department=ComboBox3.Selected.Value),JobTitle)

Upvotes: 0

Sam Nseir
Sam Nseir

Reputation: 12051

Filter(
  Office365Users.SearchUser({top:999}),
  !IsBlank(JobTitle) || StartsWith(JobTitle, ComboBox2.SearchText)
)

Please note that this will only filter after the first 999 results are returned. The searchTerm only works on display name, given name, surname, mail, mail nickname and user principal name.

Consider using SearchUserV2 as SearchUser is deprecated. https://learn.microsoft.com/en-us/connectors/office365users/#search-for-users-(v2)

Filter(
  Office365Users.SearchUserV2({top:1000}).value,
  !IsBlank(JobTitle) || StartsWith(JobTitle, ComboBox2.SearchText)
)

Upvotes: 0

carlosfigueira
carlosfigueira

Reputation: 87228

The Distinct function will return a list of distinct values of the column you specified (in your example: 'JobTitle'), but the schema of the returned table will always have a single column called 'Value'. But the records from that table will contain the values from the JobTitle column returned by Office365Users.SearchUser.

If you want to reference that column using the name 'JobTitle', you can use the RenameColumns function to do so:

Sort(
  RenameColumns(
    Distinct(
      Filter(
        Office365Users.SearchUser({searchTerm:ComboBox2.SearchText,top:999}),
        !IsBlank(JobTitle)),
      JobTitle),
    "Value",
    "JobTitle"),
  Value,
  SortOrder.Ascending)

Upvotes: 0

Related Questions