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.
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".
Then, you will be able to see an option called PowerApps for this list. Click on "Create an app" as shown below.
Name it for the app and click on "Create" as below.
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.
Go to Preview (or press F5), then click on + sign to create a new record to SharePoint list. It will navigate to editscreen1.
Expand the editscreen1, then select EditForm1, and click on fields on the right side under Properties, as shown below.
Then, unselect the rest of the columns except Name and Branch to give manual inputs.
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.
- 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: "."
- }
- })
Then, it will look like below.
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’.
Now, go to Advanced and click on Unlock to change the properties. Then, it shows more options as below.
Now, fill the variable in the Update column as shown below.
Also, expand the Datacard of CreatedBy column and select the DatacardValue of input to update with the current user variable in default as below.
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
In 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😊...