web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id : 1QlA2Vji6z9ZY6JpybuEsz
Power Apps - Building Power Apps
Answered

PowerApp to Get Supervisor of Current User

Like (0) ShareShare
ReportReport
Posted on 4 Jan 2021 21:31:38 by 21

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?

  • Jeff_Thorpe Profile Picture
    6,085 Super User 2024 Season 1 on 05 Jan 2021 at 23:37:39
    Re: PowerApp to Get Supervisor of Current 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.

  • NE0 Profile Picture
    21 on 05 Jan 2021 at 20:48:05
    Re: PowerApp to Get Supervisor of Current User

    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?

  • Verified answer
    Jeff_Thorpe Profile Picture
    6,085 Super User 2024 Season 1 on 04 Jan 2021 at 22:46:32
    Re: PowerApp to Get Supervisor of Current 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
    )

     

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

Announcing our 2025 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for…

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 791 Most Valuable Professional

#2
MS.Ragavendar Profile Picture

MS.Ragavendar 410 Super User 2025 Season 2

#3
mmbr1606 Profile Picture

mmbr1606 275 Super User 2025 Season 2

Loading complete