How to update Single or Multi person field in SharePoint from Power Apps Canvas apps

SharePoint lists and Canvas app are match made in heaven. If you are a Power Platform consultant you must have come across multiple canvas apps which use SharePoint as data source.

Today’s blog is also about using Canvas apps with SharePoint data source. In this blog, I will show you on how to dynamically set the value of Person field in SharePoint.

I have a List in SharePoint where the Stakeholder is of type Person.

Dynamically set People/ person field in SharePoint from Power Apps Canvas apps

I have a form inside my canvas app to create a list item for the Sample List. Can’t be simpler than this.

Dynamically set People/ person field in SharePoint from Power Apps Canvas apps

If you see, I have set the Stakeholder field to a specific user – App Maker. But how did I do it? And that is trick.

It’s a combobox control. So I set the DefaultSelectedItems property of the combobox to the below value.

Dynamically set People/ person field in SharePoint from Power Apps Canvas apps
{
Claims: "i:0#.f|membership|appmaker@M365x60443864.onmicrosoft.com",
DisplayName: "App Maker"
}

The important thing here is the Claims property. To dynamically set the value of the Person field, all you need is to create an object with Claims property set to the format – i:0#.f|membership|EMAIL-ADDRESS.

You need to replace EMAIL-ADDRESS which the email address of the user you want to set.

And voila! When I submit the form, the record is saved successfully with the appropriate value.

Now comes the next challenge. What if the Person field is configured to select Multi-person.

Dynamically set People/ person field in SharePoint from Power Apps Canvas apps

It’s actually quite easy. All you need to specify now is multiple values specified in the same format as earlier but represented as table. For example, in the below screenshot I have set the DefaultSelectedItems property of the combobox to a Table containing couple of Person values.

Dynamically set People/ person field in SharePoint from Power Apps Canvas apps
Table(
{
Claims: "i:0#.f|membership|carls@M365x60443864.onmicrosoft.com",
DisplayName: "Carl Smith"
}
,
{
Claims: "i:0#.f|membership|appmaker@M365x60443864.onmicrosoft.com",
DisplayName: "App Maker"
})

We are now good with user scenario for single user and multi user. But how about groups? Person field in SharePoint support groups as well.

I have created a group in my environment. The email of the group is samplegroup@M365x60443864.onmicrosoft.com

You might be wondering, you can set the Person value to this group by using the below formula.

{
Claims: "i:0#.f|membership|samplegroup@M365x60443864.onmicrosoft.com",
DisplayName: "Sample Group"
}

But if you use the above formula, it will throw an error. Instead of the above formula, use the formula below if you are setting a group.

{
Claims: "c:0o.c|federateddirectoryclaimprovider|samplegroup@M365x60443864.onmicrosoft.com",
DisplayName: "Sample Group"
}

A final note before I end this blog. While I have used the DisplayName property everywhere, it is not required. Just setting the claims property and it shall work.

Hope this helped! You will also like the below posts.

Debajit Dutta
Business Solutions MVP


Discover more from Debajit's Power Apps & Dynamics 365 Blog

Subscribe to get the latest posts sent to your email.

Discover more from Debajit's Power Apps & Dynamics 365 Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading