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 / Filter People Picker b...
Power Apps
Answered

Filter People Picker by manager

(0) ShareShare
ReportReport
Posted on by 45

Hi all

I have a datacard containing a combo box (DataCardValue49) bound to the person field of a SP List.

 

My Items property for the combo looks like this:

Choices([@'ESC-RDadd'].SPModel)

 

I have set the data fields to Primary Text = Display Name, Secondary Text = Email and SearchField = DisplayName.

IsSearchable = true.

 

This all works OK but what I really want is to filter the People Picker so that rather than return everyone in AD, it only returns the users whose manager is the email address populated in Label30.Text.

 

For example, if fred.blogs@xyz.com is populated in Label30.Text then the people picker should only be populated with users who report into fred.blogs@xyz.com.

 

I tried this but I am getting errors from Office365Users.ManagerV2 function:

 

Items Propery of combo:

Filter(Office365Users.SearchUser({searchTerm: DataCardValue49.SearchText}), Label30.Text in Office365Users.ManagerV2(Mail).mail)

 

When I set this I get a badrequest error and strangely my customizations to the people picker are reversed, meaning the Primary Text and Search field get swapped to claims and the IsSearchable field gets set back to false.

 

I would appreciate any help with this.

Thanks.

 

 

 

Categories:
I have the same question (0)
  • BCBuizer Profile Picture
    22,510 Super User 2025 Season 2 on at

    Hi @agaskelluk ,

     

    The below code pulls a table of direct reports to whatever is displayed in Label30. In case this throws an error, it will mess up the settings for the combobox since an error has different columns, so I included error handling to prevent this from happening. This is to be set as the items property of the people picker

    IfError(Office365Users.DirectReports(Label30.Text),Blank())

     

  • agaskelluk Profile Picture
    45 on at

    Hi @BCBuizer 

    I have tried similar things to your suggestion and its not working for me.

     

    I get: "The method Direct Reports has an invalid value for parameter userid".

     

    Any suggestions?

  • BCBuizer Profile Picture
    22,510 Super User 2025 Season 2 on at

    Hi @agaskelluk,

     

    When you get this error, does Label30 contain a valid value for a person that has direct reports? Can you show which part of the formula throws this error by means of a screenshot? 

  • agaskelluk Profile Picture
    45 on at

    @BCBuizer Thanks for the response. I had two cases that were causing an issue:

    1. Where the label is empty.

    - This will be the case at design time before the app runs and retrieves the records from SP.

    2. When the email address is not the same as the UPN. 

     

    DirectReports only works for the UPN not email address, so I changed the code to get the UPN from the email address. This fixes issue #2 above. 

     

    In my testing what I have found is that the people picker behaviour is very brittle. When the label is empty at design time, even If I am handling this in the formula, then it frequently resets the person card and I get the red wavy lines with an error that the id for searchUser or Direct Reports is not valid (it is blank because the label is blank at design time).

     

    Sometimes even when the id is valid the behaviour persists for a while and then it corrects itself after a delay. 

     

    Here is my formula in the items for the People Picker:

    If(!IsBlankOrError(First(Office365Users.SearchUser({searchTerm:Label30.Text})).UserPrincipalName),Office365Users.DirectReports(First(Office365Users.SearchUser({searchTerm:Label35.Text})).UserPrincipalName), Office365Users.DirectReports(Office365Users.UserProfile(User().Email).Id) )

     

    I would have expected this not to generate any issues because it is handling the case where there is nothing in the label field, but it was intermittently complaining about an invalid id being pased to DirectReports. What I am doing at the moment is checking that the person field is correctly set by updating the fields, saving and publishing immediately. Far from ideal. Perhaps the people picker simply is not suitable for this use case and I should use a different method. 

     

    Right now it appears to have settled and is working with no errors, but when I check the Person card I frequently see that the Secondary Text is empty but it was populated with Mail when I last saved it. I always make sure its correctly populated before saving and publishing.

     

    Let me know if I am missing something.

     

    Thanks

     

  • Verified answer
    BCBuizer Profile Picture
    22,510 Super User 2025 Season 2 on at

    Hi @agaskelluk ,

     

    I made a few modifications to you code:

    - changed all Office365Users functions to V2

    - replaced UserProfile(User().Mail) with MyProfileV2() 

     

    If(	
    	!IsBlankOrError(First(Office365Users.SearchUserV2({searchTerm:Label30.Text}).value).UserPrincipalName),
    	Office365Users.DirectReportsV2(First(Office365Users.SearchUserV2({searchTerm:Label30.Text}).value).UserPrincipalName), 
    	Office365Users.DirectReportsV2(Office365Users.MyProfileV2().userPrincipalName) 
    ).value
    

     

    In any case this should return the same data structure and hence not cause any disturbances to the set fields in the combobox. I tested it briefly and it seemed to work. 

     

    I even tried including a with function to simplify the code and only having to evaluate First(Office365Users.SearchUserV2({searchTerm:Label30.Text}).value).UserPrincipalName once, but this resulted in the combobox losing the field settings again, so I reversed that.

  • agaskelluk Profile Picture
    45 on at

    Hi @BCBuizer 

    Thank-you for your response. That is definitely an improvement as your code is using the V2 versions, but it does not help with my person field losing the Secondary text frequently. It has to be a bug because when I try saving after resetting the Secondary text to mail nothing happens, meaning PowerApps thinks nothing has changed. Secondary Text often loses its setting.Secondary Text often loses its setting. 

     

    I can live with this because the other two fields always keep their settings and I no longer see any design time errors.

     

    I want to thank-you for the time you spent responding to me. Your help got me back on track and eventually to a solution. Hopefully this will help someone else as well.

    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

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 765 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 272

Last 30 days Overall leaderboard