Set Default Value To Person Or Group Field In PowerApps

Problem

You can easily set the default value to the text field, and dropdown control using the 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 a Person or Group field added on it >> In the below screen, InformUsers is a Person or Group field.

So, I require that whenever users try to add a new record >> I want to keep a specific person as selected automatically (default) in the InformUsers field.

Set default vlue

Select InformUsers data card >> Click on "Unlock to change properties" from the Advanced menu >> Select the value control inside the data card as shown below >> I have selected DataCardValue66 >> From the left top side drop-down menu select "Default" property

Data card value

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 a 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: ""
}

Default

We need to set the same value to the "DefaultSelectedItems" Property as well. This is a 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.

Default selected items

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 selected by default, it can be the current user, current user's manager HR manager, etc.

Inform users

Once saved>> New list item was created in the SharePoint list with Sarvesh users saved properly in the Person or Group field.

Project tasks

Update the Person or Group field using the Patch function

If you want to update the SharePoint list item using the 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 the "Update Record" button click I am updating the record.

Screen

Add this code to your update button OnSelect Property. Depending on the configuration of your person or group field, either its single value or multi-select is allowed, and you need to provide a single record or table of records. In my case field is configured to allow multiple user selections, so I have provided a Table of records.

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: "."
        })
    }
)

Table

Summary

So, we can easily set the default value to people picker control in PowerApps Forms, and we can update the person or group field using the Patch function. You just must generate the object with the specific format which includes Claims, Email, Department, DisplayName, JobTitle, and Picture fields.

That’s it for this article. Hope this helps. Thanks for reading.


Similar Articles