Introduction
PowerApps Patch function is used to create and modify records in SharePoint. The values of specific fields are modified without affecting other properties.
In this article we will see how to create records in aSharePoint list using PowerApps Patch function with SharePoint complex columns like Lookup field, User field, and Choice field.
Example
Let's start the step by step implementation.
First we will create a SharePoint list and then we will create the above-mentioned complex fields.
Go to the PowerApps > Click on Create > Select Canvas app from blank > Set app name and select format.
Add required controls
-
Add labels for Name , Address , DOB , Lookup , Manager and Gender
-
Add Dropdown for Lookup and Manager fields
-
Text input (Single line) for Name
-
Text Input (Multi line) for Address
-
Radio button for Gender
-
Date Picker for DOB as below image.
Now set the data source to save the record in the SharePoint list.
Manager
Set Property Items - Office365Users.SearchUser() and then move to the properties on right corner > set Value - DisplayName
Lookup
Set Property Items - [Lookup List Name].Title (eg. Department.Title)
Gender
Set Property Items - ["Male","Female"]
Patch Syntax to save records in SharePoint list:
- Patch(datasource,
- Defaults(datasource),
- {
- Column name: value
- ….
- }
- )
Now we will save records in SharePoint list using Patch function as below,
- Patch('Employees Information'),
- Defaults('Employees Information'),
- {
- Title : txtName.Text,
- Address : txtAddress.Text,
- DOB:DatePicker1.SelectedDate,
- Gender: {
- '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
- Value: <radio button selected value>
- },
- Lookup:{
- '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
- Id: <Lookup ID>
- Value: <Lookup Value>
- },
- Manager: {
- '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
- Claims: "i:0#.f|membership|" & Lower(
- LookUp(
- Office365Users.SearchUser(),
- DisplayName = ddManager.Selected.DisplayName
- ).Mail
- ),
- Email: LookUp(
- Office365Users.SearchUser(),
- DisplayName = ddManager.Selected.DisplayName
- ).Mail,
- Picture: "",
- JobTitle: "",
- Department: "",
- DisplayName: ddManager.Selected.DisplayName,
- } });
Summary
In this article , we have seen how to use patch function to save records in Sharepoint with complex columns, how to connect data source, and how to map controls.
I hope this helps.
Sharing is caring.