Skip to main content

Notifications

Community site session details

Community site session details

Session Id : t4OYYqjX7fL/wxnAZQgb+4
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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,645 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 65,997 Most Valuable Professional

Leaderboard