cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
arpan_mehetre
Frequent Visitor

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
v-xida-msft
Community Support
Community Support

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

4 REPLIES 4
RusselThomas
Microsoft
Microsoft

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

v-xida-msft
Community Support
Community Support

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.

Thank you!

 

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

 

Regards,

 

Slawek

hyperbob0811
Helper II
Helper II

Thank you I finally found something which worked.

Helpful resources

Announcements
PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

Top Solution Authors
Top Kudoed Authors
Users online (2,725)