cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
New Member

PowerApp to Get Supervisor of Current User

I have an app built that grabs the current user's Supervisor and auto populates a hidden field.  This works great for users who have Supervisors assigned, but the form will NOT submit if the current users doesn't have a Supervisor assigned (such as Directors).

 

if I add this code to the 'DefaultSelectedItems', it works great.

 

If(
    EditForm1.Mode=FormMode.New,
    {
        '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
        Claims: "i:0#.f|membership|" & Office365Users.Manager(User().Email).DisplayName,
        DisplayName: Office365Users.Manager(User().Email).DisplayName
    },
Parent.Default
)

 

How to I enhance this code to add a clause which will populate the Supervisor with a default user if one doesn't exist?

1 ACCEPTED SOLUTION

Accepted Solutions
Super User
Super User

Ok, I have an idea. In the OnStart of the App set a variable that will contain the user's manger. This will be the actual manager of the user if the user doesn't have a manger. Then in the default formula use the manager variable to set the claims information. My code is a little different but I think it will work unless I have some typos.

 

If you are testing in the studio you will need to run the App > Run OnStart to get the variables set for the first time.

 

App - OnStart
Set(varGetUsersManager, Office365Users.ManagerV2(User().Email));
Set(varUsersManager, If(IsBlank(varGetUsersManager.displayName), Office365Users.MyProfileV2(), varGetUsersManager));

Try this code as the DefaultSelectedItems formula
If(
    EditForm1.Mode=FormMode.New,
    {
        '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
        Claims: "i:0#.f|membership|" & varUsersManager.userPrincipalName,
        DisplayName: varUsersManager.displayName
    },
Parent.Default
)

 



--------------------------------------------------------------------------------
If this post helps answer your question, please click on “Accept as Solution” to help other members find it more quickly. If you thought this post was helpful, please give it a Thumbs Up.

View solution in original post

3 REPLIES 3
Super User
Super User

Ok, I have an idea. In the OnStart of the App set a variable that will contain the user's manger. This will be the actual manager of the user if the user doesn't have a manger. Then in the default formula use the manager variable to set the claims information. My code is a little different but I think it will work unless I have some typos.

 

If you are testing in the studio you will need to run the App > Run OnStart to get the variables set for the first time.

 

App - OnStart
Set(varGetUsersManager, Office365Users.ManagerV2(User().Email));
Set(varUsersManager, If(IsBlank(varGetUsersManager.displayName), Office365Users.MyProfileV2(), varGetUsersManager));

Try this code as the DefaultSelectedItems formula
If(
    EditForm1.Mode=FormMode.New,
    {
        '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
        Claims: "i:0#.f|membership|" & varUsersManager.userPrincipalName,
        DisplayName: varUsersManager.displayName
    },
Parent.Default
)

 



--------------------------------------------------------------------------------
If this post helps answer your question, please click on “Accept as Solution” to help other members find it more quickly. If you thought this post was helpful, please give it a Thumbs Up.

View solution in original post

This is a creative solution that works! However, the users with no Manager see an error when the App loads:

 

Resource 'manager' does not exist or one of its queried reference-property objects are not present

 

Is there a way to suppress this red bar error?

Super User
Super User

The only thing I can think of is to use a Flow to get the Manager information, so you can gracefully handle the error. The other thing you might want to think about is making sure everyone has a manger listed in AD even if the manager is themselves.



--------------------------------------------------------------------------------
If this post helps answer your question, please click on “Accept as Solution” to help other members find it more quickly. If you thought this post was helpful, please give it a Thumbs Up.

Helpful resources

Announcements
New Badges

New Solution Badges!

Check out our new profile badges recognizing authored solutions!

New Power Super Users

Congratulations!

We are excited to announce the Power Apps Super Users!

Power Apps Community Call

Power Apps Community Call: February

Did you miss the call? Check out the Power Apps Community Call here.

Top Solution Authors
Top Kudoed Authors
Users online (53,953)