https://www.c-sharpcorner.com/article/set-default-value-to-person-or-group-field-in-powerapps/
Añadir el conector de Usuarios de Office 365 en origenes de datos
En la tarjeta:
Items: UsuariosdeOffice365.SearchUser({searchTerm:dtAuditorSegundo.SearchText;top:10})
Update: dtAuditorSegundo.Selected.Mail
En el ddl:
displayFields: ["DisplayName";"Email";"Picture"]
Seachfields: ["DisplayName"]
Items: UsuariosdeOffice365.SearchUser({searchTerm:dtAuditorSegundo.SearchText;top:10})
DefaultSelectedItems: UsuariosdeOffice365.SearchUser({searchTerm:Parent.Default})
IsSearchable: true
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.
- {
- '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
- DisplayName:User().FullName,
- Claims:"i:0#.f|membership|" & Lower(User().Email),
- Department:"",
- Email:User().Email,
- JobTitle:"",
- Picture:""
- }
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.
- Patch(
- 'Project Tasks',
- {ID: 5370},
- {InformUsers:
- Table({
- '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
- Claims: "i:0#.f|membership|" & Lower(User().Email),
- Department: "",
- DisplayName: User().FullName,
- Email: User().Email,
- JobTitle: ".",
- Picture: "."
- })
- }
- )
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.