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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / PowerApp to Get Superv...
Power Apps
Answered

PowerApp to Get Supervisor of Current User

(0) ShareShare
ReportReport
Posted on 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?

Categories:
I have the same question (0)
  • Verified answer
    Jeff_Thorpe Profile Picture
    6,085 Super User 2024 Season 1 on at

    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
    )

     

  • NE0 Profile Picture
    21 on at

    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?

  • Jeff_Thorpe Profile Picture
    6,085 Super User 2024 Season 1 on at

    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.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 519 Most Valuable Professional

#2
11manish Profile Picture

11manish 489

#3
Haque Profile Picture

Haque 327

Last 30 days Overall leaderboard