question

BobbyDJones-2098 avatar image
0 Votes"
BobbyDJones-2098 asked BenjaminChi-2862 edited

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

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.

office-sharepoint-online
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

EmilyDu-MSFT avatar image
0 Votes"
EmilyDu-MSFT answered BenjaminChi-2862 edited

@BobbyDJones-2098

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.



1.png (32.7 KiB)
2.png (13.3 KiB)
3.png (13.8 KiB)
4.png (70.2 KiB)
5.png (93.5 KiB)
6.png (9.0 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

This should include Form.Mode check to see if it’s a New form or no, only apply if it’s New, etc. thx.

0 Votes 0 ·
BobbyDJones-2098 avatar image
0 Votes"
BobbyDJones-2098 answered EmilyDu-MSFT commented

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!

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@BobbyDJones-2098

I add a new answer, please check.


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 Votes 0 ·
EmilyDu-MSFT avatar image
0 Votes"
EmilyDu-MSFT answered EmilyDu-MSFT edited

@BobbyDJones-2098

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.





1.png (32.7 KiB)
2.png (13.3 KiB)
3.png (13.8 KiB)
4.png (72.8 KiB)
5.png (90.3 KiB)
6.png (91.1 KiB)
7.png (10.5 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

BobbyDJones-2098 avatar image
0 Votes"
BobbyDJones-2098 answered

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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.