Set Default Value To Person Or Group Field In PowerApps

In this article, we will see how to set default value to person or group field OR people picker control in PowerApps forms.

Problem

 
You can easily set default value to text field, dropdown control using Default property in PowerApps forms. But how do you do it  if you want to set a specific person as selected by default in Person and Group field or People picker control? This control also has Default property but in which format do we need to provide this value, so it works correctly?
 

Solution

 
Let’s see how to achieve this.
 
Open your PowerApps app. Open the screen which has a Form with Person or Group field added on it >> In below screen, InformUsers is Person or Group field.
 
So, my requirement is that whenever users try to add a new record >> I want to keep a specific person as selected automatically (default) in InformUsers field.
 

Select InformUsers data card >> Click on "Unlock to change properties" from Advanced menu >> Select the value control inside the data card as shown below >> I have selected DataCardValue66 >> From left top side drop down meny select "Default" property
 
 
Here is the important step now >> Below is the format of data, this is how we need to set it; then only it detects it as User object and accepts the input. 
  1. {  
  2. '@odata.type'"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",  
  3. DisplayName:User().FullName,  
  4. Claims:"i:0#.f|membership|" & Lower(User().Email),  
  5. Department:"",  
  6. Email:User().Email,  
  7. JobTitle:"",  
  8. Picture:""  
  9. }

 

We need to set same value to "DefaultSelectedItems" Property as well. This isa required step, as only then will it work. >> As you can see in the below screen it shows Sarvesh users as selected already by default.
 
 
Once your changes are done >> Save the form and do a test to add a new record as shown below >> It will show Sarvesh user as selected by default. You can make any user seleted by default, it can be current user, current user's manager or HR manager etc.
 
 
Once saved>> New list item got created in SharePoint list with Sarvesh users saved properly in Person or Group field.
 
 

Update Person or Group field using Patch function

 
If you want to update SharePoint list item using Patch function and set the value to Person or group field >> You can do this using the same data format as mentioned above.
 
Below is a sample screen where the form is in Edit mode and on "Update Record" button click I am updating the record.
 
 
Add this code on your update button OnSelect Property. Depending on the configuration of your person or group field, either its single value or multiselect allowed, and you need to provide single record or table of record. In my case field is configured to allow multiple users selection, so I have provided Table of record.
  1. Patch(  
  2. 'Project Tasks',  
  3. {ID: 5370},  
  4. {InformUsers:  
  5. Table({  
  6. '@odata.type'"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",  
  7. Claims: "i:0#.f|membership|" & Lower(User().Email),  
  8. Department: "",  
  9. DisplayName: User().FullName,  
  10. Email: User().Email,  
  11. JobTitle: ".",  
  12. Picture: "."  
  13. })  
  14. }  
  15. )  
 

Summary

 
So, we can easily set the default value to people picker control in PowerApps Forms, and we can update person or group field using Patch function. You just must generate the object with specific format which includes Claims, Email, Department, DisplayName, JobTitle and Picture fields.
 
That’s it for this article. Hope this helps. Thanks for reading.