Use current user's manager as default value in a Person or Group field in SharePoint list, New Experience

Bobby D. Jones 21 Reputation points
2021-04-20T06:13:41.187+00:00

I am looking to auto populate a Person or Group field with the current user's Manager's name. I want the form to auto populate with this information, however, we need the ability to override that default hence leaving the field a Person or Group Field. I have successfully followed the instructions found here use-current-user-as-default-value-in-a-person-or-g.html

for setting the current user in the Person or Group Field, but I need to be able to set the Manager for that user as well.

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
9,666 questions
0 comments No comments
{count} votes

Accepted answer
  1. Emily Du-MSFT 41,791 Reputation points Microsoft Vendor
    2021-04-20T11:39:51.753+00:00

    @Bobby D. Jones

    You need to set the manager for the current user first. Then follow below steps to achieve this.

    1.Go to your list -> Power Apps -> Customize forms.
    2.Click Data -> Add data -> Search Office 365 Users -> Add a connection.

    89460-1.png
    89499-2.png
    89500-3.png

    3.Click FormScreen1 in the left Tree view -> Advanced on the right -> OnVisible -> Fill the text box with following code.

    89561-4.png

    {  
       '@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",  
       Claims:"i:0#.f|membership|" & Office365Users.Manager(User().Email).Mail,  
       DisplayName: Office365Users.Manager(User().Email).DisplayName,  
       Email: Office365Users.Manager(User().Email).Mail  
     }  
    

    4.Click the people or group field DataCard (which is named Manager_DataCard1 in my example) on the left Tree view -> DataCardValue2 -> Advanced on the right -> DefaultSelectedItems -> Fill the text box with following code.

    89487-5.png

    {  
       '@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",  
       Claims:"i:0#.f|membership|" & Office365Users.Manager(User().Email).Mail,  
       DisplayName: Office365Users.Manager(User().Email).DisplayName,  
       Email: Office365Users.Manager(User().Email).Mail  
     }  
    

    5.Result.

    89527-6.png


    If an Answer is helpful, please click "Accept Answer" and upvote it
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


3 additional answers

Sort by: Most helpful
  1. Bobby D. Jones 21 Reputation points
    2021-04-20T15:13:17.933+00:00

    This does exactly what I want, except now it breaks my autocomplete for the current user. I am sure it has something to do with how to format the code in the OnVisible field. I have:

    UpdateContext({  
         CurrentUser: {  
             '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",  
             Claims: "i:0#.f|membership|" & Lower(User().Email),  
             Department: "",  
             DisplayName: User().FullName,  
             Email: User().Email,  
             JobTitle: ".",  
             Picture: "."  
         }  
     }) 
     ({
        '@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
        Claims:"i:0#.f|membership|" & Office365Users.Manager(User().Email).Mail,
        DisplayName: Office365Users.Manager(User().Email).DisplayName,
        Email: Office365Users.Manager(User().Email).Mail
      })
    

    How should this be formatted so that both auto complete fields/code works? Thank you!


  2. Emily Du-MSFT 41,791 Reputation points Microsoft Vendor
    2021-04-21T10:04:34.723+00:00

    @Bobby D. Jones

    You need to use two people or group fields to display current user and manager respectively. Here’re steps:

    1.Go to your list -> Power Apps -> Customize forms.
    2.Click Data -> Add data -> Search Office 365 Users -> Add a connection.

    89933-1.png
    89934-2.png
    89867-3.png

    3.Click FormScreen1 in the left Tree view -> Advanced on the right -> OnVisible -> Fill the text box with following code.

    89899-4.png

    UpdateContext({    
         CurrentUser: {    
             '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",    
             Claims: "i:0#.f|membership|" & Lower(User().Email),    
             Department: "",    
             DisplayName: User().FullName,    
             Email: User().Email,    
             JobTitle: ".",    
             Picture: "."    
         }    
     })  
    

    4.Click the people or group field DataCard(which is named Current user_DataCard1 in my example) on the left Tree view -> Advanced on the right -> Click on unlock to change properties -> Fill the variable to “CurrentUser” in the Default field.

    89900-5.png

    5.Click the people or group field DataCard (which is named Manager_DataCard1 in my example) on the left Tree view -> DataCardValue3 -> Advanced on the right -> DefaultSelectedItems -> Fill the text box with following code.

    89935-6.png

    {  
        '@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",  
        Claims:"i:0#.f|membership|" & Office365Users.Manager(User().Email).Mail,  
        DisplayName: Office365Users.Manager(User().Email).DisplayName,  
        Email: Office365Users.Manager(User().Email).Mail  
    }  
    

    6.Save and publish the form to the SharePoint.
    7.Result.

    89941-7.png


    If an Answer is helpful, please click "Accept Answer" and upvote it
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  3. Bobby D. Jones 21 Reputation points
    2021-04-21T16:46:58.58+00:00

    That is awesome, thank you for the follow up. I also figured out this code for OnVisible of 'FormScreen1' and created two variables to use in my "Default" fields for both items:

    UpdateContext({  
         CurrentUser: {  
             '@odata.type': 
             "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",  
             Claims: "i:0#.f|membership|" & Lower(User().Email),  
             Department: "",  
             DisplayName: User().FullName,  
             Email: User().Email,  
             JobTitle: ".",  
             Picture: "."  
         },  
          UserManager: {
            '@odata.type':
            "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
            Claims:"i:0#.f|membership|" & 
            Office365Users.Manager(User().Email).Mail,
            DisplayName: Office365Users.Manager(User().Email).DisplayName,
            Email: Office365Users.Manager(User().Email).Mail
         }
      })
    

    "CurrentUser" is the default setting for my Employee Name, and "UserManager" is the default for the Manager Name. Thank you again for your assist, could not have done it without you.

    0 comments No comments