Set Current User As Default Value Of Person/ Group Field In PowerApps

Introduction

In this article, I am going to explain how to set a current user as the default value of the person or group field in PowerApps. The goal of this article is to provide a complete idea of how to set current user or user-related properties to SharePoint person or group column in PowerApps.

Overview

  • Fetch the current user properties on screen load
  • Set the properties to the SharePoint list columns on button click.

Procedure

Create a SharePoint list with a people/group column

I have created a SampleList here with the following 3 columns.

  • Name
  • Branch
  • CreatedBy

    SharePoint list with a people/group column

Here, our goal is to set the current user as the default value to the CreatedBy column and the remaining Name and Branch columns will be filled by using input forms.

Create a PowerApp for the above list

Click on "Exit Classic Experience".

Exit Classic experience

Then, you will be able to see an option called PowerApps for this list. Click on "Create an app" as shown below.

create an app

Name it for the app and click on "Create" as below.

create an app

I have named it Myapp. The moment you clicked on ‘Create’, it will take you to PowerApps Studio where you will design and develop the actual app.

What to do in PowerApps Studio

By default, you will get 3 screens called BrowseScreen1, DetailedScreen1, and EditScreen1respectiveluy, with all functionalities, as shown below.

PowerApps studio

Go to Preview (or press F5), then click on + sign to create a new record to SharePoint list. It will navigate to editscreen1.

create new record to SharePoint list

Expand the editscreen1, then select EditForm1, and click on fields on the right side under Properties, as shown below.

properties

Then, unselect the rest of the columns except Name and Branch to give manual inputs.

Exit Classic experience

Now, we need to set user properties on screen load for CreatedBy column.

Set user properties on screen load

For this, you need to select the EditScreen1 and click on Advanced as it shows on the right side. Then, you will get OnVisible under ACTION. Now, you need to fill the OnVisible input with the following code.

  1. UpdateContext({  
  2.     CurrentUser: {  
  3.         '@odata.type'"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",  
  4.         Claims: "i:0#.f|membership|" & Lower(User().Email),  
  5.         Department: "",  
  6.         DisplayName: User().FullName,  
  7.         Email: User().Email,  
  8.         JobTitle: ".",  
  9.         Picture: "."  
  10.     }  
  11. }) 

Then, it will look like below.

Set user properties on screen load

Where CurrentUser is a user-defined variable and DisplayName, Department, Email etc. are the user properties.

Now, select the CreatedBy Column and put the Visible as ‘Off’.

Visible as ‘Off’

Now, go to Advanced and click on Unlock to change the properties. Then, it shows more options as below.

change properties

Now, fill the variable in the Update column as shown below.

variable in the Update column

Also, expand the Datacard of CreatedBy column and select the DatacardValue of input to update with the current user variable in default as below.

DatacardValue

Here, CurrentUser is our defined variable, having all the properties. Then, save the app and submit the new record by filling Name and Branch manually, and the createdBy column will get filled by the current user's name.

Result

CurrentUser

In SharePoint list,

SharePoint list

Hence, we have set the current user to the default value of people or group column.

Conclusion

This article will help us to set the current user as the default value to the people/group column in PowerApps.

Thank you😊...


Similar Articles