cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
bwebs
Level: Powered On

Get Manager based on another people lookup

Hi, 

 

I have built a Powerapp to store fields of information on an employee. I have a people lookup field called "Associate", works fine. I have another field called Manager, which I have figured out how to auto-populate according to the current user by this:

 

If(Form2.Mode=New,Office365Users.Manager(User().Email).DisplayName)

 

What I need is based on the user selected on the "Associate" people lookup, auto-populate the manager field based on the person selected in the associate field. What would be the proper method to code this? What I have tried does not work so far. Any assistance would be greatly appreciated. 

2 ACCEPTED SOLUTIONS

Accepted Solutions
MartinWoe
Level: Powered On

Re: Get Manager based on another people lookup

Hi,

 

if you have a combo box called "PeopleLookup" where you have your "Associates" in, and a label where you'd like to display the manager's name you could go like that:

 

Set text property of label to 

 

Office365Users.ManagerV2(First(PeopleLookup.SelectedItems).Mail).displayName

 

In Detail:

Office365Users.ManagerV2: Call lookup for manager, field expects email or ID to be filled in

First(PeopleLookup.SelectedItems).Mail: use first result from People Lookup and return Mail address

.displayName: Return Managers displayName in label

Highlighted
bwebs
Level: Powered On

Re: Get Manager based on another people lookup

Ok, so this is what worked: 

 

If(IsBlank(DataCardValuexxx),"",Office365Users.ManagerV2(First(DataCardValuexxx.SelectedItems).Email).displayName)

 

No errors, great! Smiley Happy

9 REPLIES 9
MartinWoe
Level: Powered On

Re: Get Manager based on another people lookup

Hi,

 

if you have a combo box called "PeopleLookup" where you have your "Associates" in, and a label where you'd like to display the manager's name you could go like that:

 

Set text property of label to 

 

Office365Users.ManagerV2(First(PeopleLookup.SelectedItems).Mail).displayName

 

In Detail:

Office365Users.ManagerV2: Call lookup for manager, field expects email or ID to be filled in

First(PeopleLookup.SelectedItems).Mail: use first result from People Lookup and return Mail address

.displayName: Return Managers displayName in label

Community Support Team
Community Support Team

Re: Get Manager based on another people lookup

bwebs
Level: Powered On

Re: Get Manager based on another people lookup

Hi, 

 

I tried both proposed solutions, and while it pulls the manager name on runtime I get the error: invalid value for parameter "id".

 

This is the exact value I am using for the default text box: Office365Users.Manager(DataCardValue3.Selected.Email).displayName

 

The DataCardValue3 is the "Associate" people selector, when you enter the name, the manager fields auto-populates fine. However the error upon clicking submit. 

 

Any ideas? I am trying several things. 

 

 

 

bwebs
Level: Powered On

Re: Get Manager based on another people lookup

Hi, 

 

I tried both proposed solutions, and while it pulls the manager name on runtime I get the error: invalid value for parameter "id".

 

This is the exact value I am using for the default text box: Office365Users.Manager(DataCardValue3.Selected.Email).displayName

 

The DataCardValue3 is the "Associate" people selector, when you enter the name, the manager fields auto-populates fine. However the error upon clicking submit. 

 

Any ideas? I am trying several things. 

mwoelzmueller
Level: Powered On

Re: Get Manager based on another people lookup

Seems like your associate field is combobox? If this is the case you cannot just call the email value as combobox may have multiple values. Therefore I used „first“ to gather the first record. Also please use managerV2.
Please try and let me know.
bwebs
Level: Powered On

Re: Get Manager based on another people lookup

I used this: Office365Users.ManagerV2(First(DataCardValue3.SelectedItems).Email).displayName

 

It works for the display of the manager name but gives a runtime error about invalid ID for the manager when submitting. Still working with it. 

mwoelzmueller
Level: Powered On

Re: Get Manager based on another people lookup

Do you use it in a form? The error appears after submittal? So the error is shown once the input field is empty as the ID doesn‘t receive a valid mail. You should wrap it in an if clause.

As I‘m on mobile I cannot give the right code but still an idea. Do something like
If(IsBlank(InputField), „NONE“, the code you already have)
bwebs
Level: Powered On

Re: Get Manager based on another people lookup

I am trying this, and will reply back after some testing. 

Highlighted
bwebs
Level: Powered On

Re: Get Manager based on another people lookup

Ok, so this is what worked: 

 

If(IsBlank(DataCardValuexxx),"",Office365Users.ManagerV2(First(DataCardValuexxx.SelectedItems).Email).displayName)

 

No errors, great! Smiley Happy