PowerApps People Picker default selection

PowerApps: Select Current User by Default

Premise

In this post I’ll demonstrate how to select the current logged in user, by default, in Microsoft PowerApps.

Solution

This can be achieved by using the in-built PowerApps function, User(). However, the way to extract value out of it can be different depending upon the base controls. So, let’s check out how to extract value, of the current logged in user, for the following controls: –

  • People Picker/ User field
  • Text field

People Picker

People Picker field is associated with a People or Group meta-data type. This is a complex data type and expects a pre-formatted JSON value only. 

To modify/set a user field from code, we need to supply a pre-formatted JSON value

To set the default value of a User field, select the People Picker card in PowerApps and, paste the following code in the Default property.

If(Form1.Mode = New,{
  '@odata.type':"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
   Claims:Concatenate("i:0#.f|membership|",User().Email),
   DisplayName:User().FullName,
   Email:User().Email
    }, 
ThisItem.Creator)

The above code block can be explained as following:-

  • Form.Mode = New: A condition is checked to apply the default setting for new forms only. This will allow users to change the default selection, if they want.
  • User().Email: This is a PowerApps in-built function which automatically provides the logged in user’s detail.
  • ThisItem.Creator: Creator is the name of the SharePoint field. Modify this name with the appropriate field name being used.

Text

For text fields, it’s fairly simple. Just use the following in the default property of the control and not the card.

For text controls, modify the default property of the control and not the card.

Just expand the card and set the default property of the underlying value control to the following.

User().Email
//OR
User().FullName

Running the application will automatically fill in both the values with an edit option.

PowerApps Default User Selection
PowerApps Default User Selection

Key Takeaways

  • Since, the code only executes for new form, make sure to set the Mode property of the underlying form to New.
  • User field is a complex one. Hence, we cannot directly update it. We need to pass in the customized JSON formatted value only.

One thought on “PowerApps: Select Current User by Default

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.