cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
arpan_mehetre
Level: Powered On

Auto populate person type column with logged in user

I want to auto-populate my Person type drop down with current logged in user. I went over the other threads for the same scenario and tried using - Office365Users.MyProfile() also Office365Users.MyProfileV2() but it is not populating any values in the dropdown.

 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support Team
Community Support Team

Re: Auto populate person type column with logged in user

Hi @arpan_mehetre,

 

Do you add a SP list as a data source within your app?

Do you want to auto-populate the Person type column with current login user when you open a New form (add a new record) within your app?

 

I think it is not necessary to add a Office 365 Users connector within your app, the User function could achieve your needs.

 

I have made a test on my side, please take a try with the following workaround:5.JPG

 

 

  • Unlock the Data card control which contains the Person type column.
  • Set the DefaultSelectedItems property of the Combo box control to following formula:
If(
    EditForm1.Mode=FormMode.New,
    {
     '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
      Claims: "i:0#.f|membership|"&User().Email,
      DisplayName: User().FullName
    },
    Parent.Default
)

More details about the User function in PowerApps, please check the following article:

User function

 

In addition, if the Person type column in your SP list allowes multiple values, please take a try with the second solution @RusselThomas mentioned.

 

 

Best regards,

Kris

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
Super User
Super User

Re: Auto populate person type column with logged in user

hi @arpan_mehetre,

 

Check out this blog by Carlos, should have all the answers you need.

Specifically, the person column section as follows;

 

Person columns

The idea for setting defaults in Person is similar to the other column types, but for person you need to specify one field that uniquely identifies the user within the Office 365 (and Active Directory) tenant that hosts the SharePoint list - you can have two people with the same name, so that should not be an option. What is used in this case is the 'Claims' property of the person object, which has a not-very-user-friendly format. I've found that the best way to figure out the value that you need to use is to add a label control whose Text property shows the value of that Claims for the selected person:

Retrieving the value for the Claims property

This format shown above is common for most Person objects in SharePoint, so if you want to set the logged in user as the default value for a Person column, you would use the following expression:

If(
    EditForm1.Mode = FormMode.New,
    {
        DisplayName: myself.FullName,
        Claims: "i:0#.f|membership|" & myself.Email
    },
    Parent.Default)

Where myself is defined in the OnVisible property of the screen (or in the OnStart property of the app) as

Set(myself, User())

Notice that there are a few domains where the value of User().Email does not correspond to the user's e-mail (in tenants where the e-mail and the UPN are different), so if this is your case, you can use the Office 365 Users connection with the MyProfileV2 function.

Another issue to be aware: some Person objects also support the usage of groups:

Allow selection of groups in a Person column

In this case, the common pattern of creating the Claims value based on the e-mail will likely not work, so you'll need to see what is the claims for the group you want to set as a default selection (for example, using the technique shown above to find the pattern) to get the value that is needed for the Claims property.

For Person columns with multiple selection the process is similar, but you need to use a table instead of a single record. If you want to set the default value for the user and their manager, then you can use the Office 365 Users connector to retrieve it: in the initialization (screen's OnVisible or app's OnStart) you'd have this expression:

Set(myself, Office365Users.MyProfileV2());
Set(manager, Office365Users.Manager(myself.id))

And on the DefaultSelectedItems for the combo box control, you can use this expression:

If(
    EditForm1.Mode = FormMode.New,
    Filter(
        Table(
            {
                DisplayName: myself.displayName,
                Claims: "i:0#.f|membership|" & myself.mail
            },
            {
                DisplayName: manager.DisplayName,
                Claims: "i:0#.f|membership|" & manager.Mail
            }),
        Not(IsBlank(DisplayName))),
    Parent.Default)

The Filter that wraps the Table function is needed in case you have a person with no manager (such as the CEO), and you don't want them to see a selection that is empty.

 

Hope this helps, and kudos to Carlos for a great blog!

 

RT

Community Support Team
Community Support Team

Re: Auto populate person type column with logged in user

Hi @arpan_mehetre,

 

Do you add a SP list as a data source within your app?

Do you want to auto-populate the Person type column with current login user when you open a New form (add a new record) within your app?

 

I think it is not necessary to add a Office 365 Users connector within your app, the User function could achieve your needs.

 

I have made a test on my side, please take a try with the following workaround:5.JPG

 

 

  • Unlock the Data card control which contains the Person type column.
  • Set the DefaultSelectedItems property of the Combo box control to following formula:
If(
    EditForm1.Mode=FormMode.New,
    {
     '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
      Claims: "i:0#.f|membership|"&User().Email,
      DisplayName: User().FullName
    },
    Parent.Default
)

More details about the User function in PowerApps, please check the following article:

User function

 

In addition, if the Person type column in your SP list allowes multiple values, please take a try with the second solution @RusselThomas mentioned.

 

 

Best regards,

Kris

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Highlighted
TheSlawekG
Level: Powered On

Re: Auto populate person type column with logged in user

Thank you!

 

I've tried a few solutions from this website and blogs and none of them was working but your!

 

Regards,

 

Slawek

Helpful resources

Announcements
thirdimage

Power Apps Super User Class of 2020

Check it out!

thirdimage

Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

SecondImage

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Top Solution Authors
Top Kudoed Authors (Last 30 Days)
Users online (2,781)